- Home /
Networked Objects not appearing on Client when Client loads scene first
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[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);
}
Thanks!
Answer by inconaks · Sep 07, 2016 at 06:34 PM
Setting minimum players in the lobby manager settings to the exact amount of players that will play did the trick for me.
Edit: it's not the case, it sometimes works and sometimes not.
Your answer
Follow this Question
Related Questions
UNet ClientRPC does not fire 2 Answers
UNET - Syncing prefabs spawned by clients. 3 Answers
Can MLAPI connect to a standalone server written in another language (Go) 0 Answers
Unet: Client/Server end up with two different animations 0 Answers
ClientRpc Function not being carried out on all clients in Unity3d c# 0 Answers