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 playtesting 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 *!= null)*
{
(lobbySlots as CharacterSelect).RpcUpdateCountdown(floorTime);
}
}
}
}
for (int i = 0; i < lobbySlots.Length; ++i)
{
if (lobbySlots != null)
{
(lobbySlots as CharacterSelect).RpcUpdateCountdown(0);
}
}
ServerChangeScene(playScene);
}
Thanks!