Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sync scene loading for all clients using NetworkManager

Tags:

I'm creating a 2D game for iOS. My game uses a host and client approach for a two player versus game in LAN. The host waits for a client then after loads the next scene. The problem is the scene loading is not synced for both players. The scene starts earlier than the other. I want to wait for all players to load the scene before any other work.

My NetworkManager has no online and offline scene assigned. No playerPrefab also because it will be added dynamically. I'm using ServerChangeScene(). I'm rather new to Unity and networking so any help is appreciated.

public override void OnServerConnect (NetworkConnection conn)
{
    base.OnServerConnect (conn);

    print ("OnServerConnect");

    //not localclient(host)
    if (client != null && client.connection != conn) {
        ServerChangeScene ("PlayScene");
    }
}
like image 243
kredj Avatar asked Jun 23 '16 17:06

kredj


1 Answers

Okay since no answers, I handled this using custom messages. I made a loading screen that loads async the "PlayScene" and set its allowSceneActivation to false. When the client calls OnClientSceneChanged(), he will send a message to the server that its done loading the scene. The server will loop through all the clients to check if all have finished loading the scene and will reply that all clients are now ready for scene activation.

like image 72
kredj Avatar answered Sep 28 '22 04:09

kredj