Start() called multiple times by the MasterClient

Options
Hi, I've been trying to recreate the Asteroids Demo on my own and I'm having some troubles with the players instantiation.

I'm having players join a lobby like in the demo, then the MasterClient use PhotonNetwork.LoadLevel(1);
In this new scene I have a GameManager script with the usual unity Start() function.
Inside there is
 Debug.Log("Here with " + PhotonNetwork.LocalPlayer.ActorNumber);
        Hashtable props = new Hashtable
        {
            {PlayerConst.PLAYER_LOADED_LEVEL, true}
        };
        PhotonNetwork.LocalPlayer.SetCustomProperties(props);
And if I have 3 players in my room before switching to the game scene, I can see 3 debugs with the MasterClient ActorNumber.
Then the Player instanciation of the MasterClient is done 3 times as well, but it works well for the other players in the room.

Seems like my GameManager has N instances for the MasterClient (where N is the number of players in the room).
Anyone know what I did wrong to have this kind of behaviour ?

Thanks for the help.

Comments

  • YakiCL
    Options
    So, I've found the problem but I don't understand the behaviour behind it.
    The reason my player spawning was called multiple times is because I suscribed to the CountdownTimerHasExpired event multiple times, because OnEnable was called multiple times while the loading of the scene (one for each player in the room).

    I simply added the line CountdownTimer.OnCountdownTimerHasExpired -= OnCountdownTimerIsExpired; in OnDisable() to make it work.

    I still don't understand why the scene is reloaded in the MasterClient session for each player in the room.
    Shouldn't the scene be loaded only once for everyone ?
  • Komrade
    Options
    Bump for this thread. I have seen multiple issues that seem to stem from the fact that the scene is reloaded every time a player joins the room.

    https://forum.photonengine.com/discussion/9878/photon-onloadedlevel-start-called-twice-on-client

    Whoever answered that seems to understand why it's happening, but I haven't been able to find anywhere the cause for the multiple scene loads