Search Unity

UNET Issues - Multiplayer on Devices is not working

Discussion in 'Editor & General Support' started by PlayMagicLtd, May 10, 2016.

  1. PlayMagicLtd

    PlayMagicLtd

    Joined:
    Aug 23, 2012
    Posts:
    48
    Hello

    We are working on doing implementing online multiplayer for a game using UNET. We got it to work perfectly on the editor, but on the device we have some very strange issues that happen only when we are trying to be a client. Some of them are as strange as an if statement not being executed on the device. All sorts of workarounds have been applied, but just lead to more issues.

    Although I am not sure, what exactly started causing these problems, as this was working fine before, but from what I am aware, certain changes to joining of the game probably caused this to happen. The server and the client exchange a few messages with each other in the beginning to pass data about the team they selected etc before they game goes into the online scene. This is the flow of what happens:

    1. Server hosts

    2. Client joins

    3. Server waits for client to select its team (for debug, we dont wait)

    4. Scene changes

    5. We wait for the scene to be loaded on all clients and catch that in the OnServerSceneChanged. From here we send a message to clients to indicate scene has loaded for all clients

    6. All the clients upon receiving the message, add their players, and wait for objects in the scene to be fully created, with the start function being called (this was done because of a strange issue on the device, explained below*), and send a message to the server to indicate all is ready

    7. The server, then upon receiving this message, spawns the networked objects.

    8. The spawned objects wait for the player objects get the authority message (call to the OnStartLocalPlayer), and then make the game step into the game loop on the server side and client side,

    This is the general flow that exists now. The changes made to the flow were, making the server wait for both clients to finish loading their scenes before sending a message to the clients to spawn their players. Before that, the clients spawned their players in OnClientSceneChanged. This was causing issues with timing so I had to make sure they are done at the same time. After this this is the list of the issues that happened. All these happen only when the device is a client:

    1. The GameObject.Find to fetch the NetworkManager in the online scene was failing for no reason whatsoever. Worked around this by using the static instance of the Network Manager

    2. On the client side, a certain object in the scene (static object), has it's start function being called after the call of the Start of one of the Networked Objects instantiated by the server. This was causing issues, so i forcefully made the client wait for the start to be called before sending a ready to the server. That seemed to have fixed it

    3. A static variable that counts the players spawned before the game manager starts updating returns a wrong value, for no reason. Got by this, by removing the counter and using a bool that is triggered instead

    4. Now, something as a simple as an if condition refuses to work on the device. This is really really strange.

    All of these issues happen only if the device is a client. If we make the device a server and the editor as a client, it works all normally.

    There is not much I can do when a simple if condition fails to execute. I tried using a development build etc, but made no difference. Now I can go back try changing the things that I think triggered this off, but we really need some help here to figure out what is going on.

    Cheers
     
    Last edited: May 10, 2016