Is there a way to check which scene the host is in?
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Is there a way to check which scene the host is in?
Klover
2022-03-28 18:04:54
I'm making a game where there are several scenes any player can be in, but when joining a room I want to load the scene that the host is in of course. Any clue how this is done?
Comments
If players are not in the same scene, maybe they don't need to be online in the same room.
Keep in mind: When you join a room, all networked objects are being instantiated, no matter which scene the owner is in. The positions are also not scene-based. We put some work into finishing loading the same scene as everyone is using, which is complicated enough. PUN 2 does not really support multiple scenes, so .. you are entering uncharted territory.
The best tip I can give in this case is that the Master Client could set some room property with the scene this client is in. Maybe you even get rid of using PhotonViews (and just use RaiseEvent to sync position updates in Interest Groups, etc.)...
@Tobias Are you saying that I can set some public RoomOptions() that can identify the scene the host is in? Like if I wanted to join their scene I could check which scene they're in by joining the Photon room then accessing RoomOptions().SceneName or something?
@Tobias I read this in the documentation CustomRoomPropertiesForLobby = new string[0] under RoomOptions()
Custom Room Properties would be the main keyword to check in the docs.
In theory, you could have this property be included in room lists (in the Photon matchmaking lobby). But the update frequency for the room lists is very very low and if the Master Client changes scenes frequently, this won't be properly reflected in the lobby.
Better join the room, get the properties, load the fitting scene. Basically what PhotonNetwork.LoadScene and the setting PhotonNetwork.AutomaticallySyncScene does but as "one time" workflow (only when joining the room).
@Tobias One more thing, if I use SceneManager.LoadScene instead of PhotonNetwork.LoadLevel, will everything in the Photon Room be synced regardless or is it essential that I use PhotonNetwork.LoadLevel for everything to run smoothly?
Our LoadLevel takes care of the logistics that lead to loading the scene. It pauses dispatching of incoming messages and sending of outgoing ones. It loads the scene the Master Client set and resumes dispatch/send when that's done.
As long as the clients know the networked objects everyone has, you can load scenes any ways you like.
The docs should have more details. The complete page may be of interest.
Back to top