Joining Random Room Problem

Options
Greetings.
I am a member of a new game dev team and we are developing a multiplayer game using Photon.
We have all players entering random rooms using the JoinRandomRoom() function, and are trying to override the OnJoinedRoom() callback to switch the BGM and load the scene. However, this seems to work only when the player turns out to be the master client. If a player lands into an existing room, however, the scene appears to be opened instead by some code in the JoinRandomRoom() function, and the OnJoinedRoom() callback doesn't get called at all. As a result, on all players except for the master client, the Main Menu BGM keeps playing and doesn't switch to the in-game BGM. I would be grateful if I could be informed of a workaround to this issue.
Many thanks in advance.

Comments

  • Hi @Zerobi,

    do you use PhotonNetwork.automaticallySyncScene? If so, do you call PhotonNetwork.LoadLevel on the MasterClient? In this case, the MasterClient will update the Custom Room Properties and add the current level name to it. Any client who joins later, will receive those updated Properties and start loading the scene. I'm currently not sure, if this might skip the OnJoinedRoom callback because the GameObject, this component is attached to, might get destroyed due to scene loading.

    To workaround this problem, you have different possibilities. The first one would be, to attach a script to the GameObject with the attached Audio Source and use it's OnDisable or OnDestroy function to stop playing the audio clip. The second one would be, to disable PhotonNetwork.automaticallySyncScene option and think about a similar solution or handle scene loading on your own. A third option would be, to mark the GameObject with the attached OnJoinedRoom callback as DontDestroyOnLoad and remove it yourself, after the scene has been loaded (and if you don't need that object any longer).