One Room, Multiple scenes - players in different scenes.

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.

One Room, Multiple scenes - players in different scenes.

LupineYonderboy
2014-06-25 07:32:33

Hi All,

(I am re posting this question here from the .net section as I believe this is a more relevant board, I did try, but I could not find any way to move it. )

Quick background info: c# developer working in Unity 3D, creating a game that spans multiple scenes, looking to implement internet based 4 player co-op.

First off – sorry if this a much repeated question – I have looked for the answer, but cant seem to find anything that satisfies.

So, been digging around in the examples and watched some youtube tutorials and implemented a simple login for our game. All is good and liking it all so far, but I have a question that I cannot find an answer to in the forum. (Which does not mean that it does not exist. ;) )

Sooo....Noob Pun Question: Is it possible to create a room that spans all the scenes in the game? E.G. A Player creates a room, joins as first player and moves from scene 1 to scene 3. Can a new player join that same room, start at scene 1 and then move to scene 3 to join his friend?

I have created a hacked version of the above (the ability to have multiple players in different scenes) but found I had to make a new room as I entered a new scene, which meant new rooms were then appearing on lobby room list.

Or is there a way to only display the initial lobby room in the lobby room list and hide all rooms created there after, that are related to first room?

Any help or advice about best practices, pointers to tutorials, or pointers to existing forum posts that cover this topic would most welcome and very much appreciated.

Many Regards and thanks in advance.

Comments

Tobias
2014-06-27 10:39:19

The room is independent from the loaded scene. You can load scenes at will.

There are a few things to keep in mind though: When you load, Unity will destroy the content of the current scene. This includes the characters others network-instantiated and any scene object that has a PhotonView on it. The Editor Scripts of PUN currently assign the IDs to PhotonViews, starting at 1 per scene. This means: If player A is in scene 1, the PhotonView #1 might relate to another object than player B's PhotonView #1, which might be on an entirely different scene object. You should be able to set the ViewID per PhotonView in the editor, to avoid confusion. The position any player sends is based on world coordinates and does not include a reference to the scene. If all your scenes are centered at 0,0,0, the positions of remote players might not be accessible in the scene you loaded.

So. Loading different scenes per client is definitely possible but you might run into some extra issues.

Luisdmo
2020-05-10 07:19:15

How can i do that?

Luisdmo
2020-05-10 07:19:48

im making a 2D card game but its imposible to play if everty player get on the same scene

CowWalkingOnUdders
2021-06-26 13:55:36

im not an expert but here's how i do it
simply load level with photonneworking

PhotonNetwork.LoadLevel(_scene_name);

Then call a RPC function to destroy that networked character. For me, I created these 2 functions to do the job

public virtual void change_level()
{
photonView.RPC("update_player_inGame", RpcTarget.All);
}

how you call "change_level" function is up to you

Note:
be careful when using "Dontdestroyonload"
one of the reasons why you might still see other player character is because you set "Dontdestroyonload" to that object. For me, I only need the "Player" object that a client controls to be "immortal"
so in my object initialization function (either start (), awake (), or something else) I use this

if (photonView.IsMine)
{
DontDestroyOnLoad(this.gameObject);//when change scene, don't destroy on load
}

i am no expert and my answer may very well be ineffective or even wrong, so if someone got a better answer, please share them.

Thanks in Advance!!!
CWO

Back to top