2

I'm having an issue with object instantiation in my multiplayer game. The game layout is simple: Players enter a lobby and once everyone marks ready there is a countdown and the LobbyManager calls ServerChangeScene(gameScene) to load the game level. The problem is that on a lot of the loads all of the networked objects are not instantiating on the client. After a bit of play testing I noticed that this seems to only happen when the client loads up the scene before the server - when the server loads first everything appears correctly and the game plays as it should. Is there a way to ensure the server loads first?

Some code for reference:

 public override void OnLobbyServerPlayersReady()
 {
     currentNumberTeam1 = 0;
     currentNumberTeam2 = 0;
     StartCoroutine(ServerCountdownCoroutine());
 }
 public IEnumerator ServerCountdownCoroutine()
 {
     float remainingTime = _matchStartCountdown;
     int floorTime = Mathf.FloorToInt(remainingTime);
     while (remainingTime > 0)
     {
         yield return null;
         remainingTime -= Time.deltaTime;
         int newFloorTime = Mathf.FloorToInt(remainingTime);
         if (newFloorTime != floorTime)
         {
             floorTime = newFloorTime;
             for (int i = 0; i < lobbySlots.Length; ++i)
             {
                 if (lobbySlots[i] != null)
                 {
                     (lobbySlots[i] as CharacterSelect).RpcUpdateCountdown(floorTime);
                 }
             }
         }
     }
     for (int i = 0; i < lobbySlots.Length; ++i)
     {
         if (lobbySlots[i] != null)
         {
             (lobbySlots[i] as CharacterSelect).RpcUpdateCountdown(0);
         }
     }

     ServerChangeScene(playScene);
 }
shilovk
  • 11,718
  • 17
  • 75
  • 74
Ken
  • 21
  • 2

0 Answers0