Is there a way to check which scene the host is in?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

Tobias
2022-03-29 14:46:55

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.)...

Klover
2022-03-30 06:52:00

@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?

Klover
2022-03-30 06:52:52

@Tobias I read this in the documentation CustomRoomPropertiesForLobby = new string[0] under RoomOptions()

Tobias
2022-03-30 08:48:34

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).

Klover
2022-03-30 16:13:06

@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?

Tobias
2022-03-31 15:51:04

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