Persisting Room Object between levels

Options
Hi,

I used InstantiateRoomObject to create objects representing games and players. I have multiple Scenes that players use to customise these objects before playing the game, so I'd like these objects to stay available even when I load a different level.

From what I've read in the documentation it sounds like these room objects exist until destroyed, or the room is destroyed, so calling PhotonNetwork.LoadLevel shouldn't destroy them. Have I understood that correctly? If so that leads to my next question, how should I access the room object in the next scene, as it doesn't appear in my Scene Hierarchy.

Thanks for reading.

Best Answer

Answers

  • Jimbo
    Options
    After looking into the source files, it seems that despite being called room objects, they have to be destroyed when the scene changes. I think the old name of "scene objects" describes them better, but there you go.

    I guess that means I'll have to hope that Custom Room Properties is enough to hold all my player data. If there is a way to keep an object into the next scene, like DontDestroyOnLoad, then please do let me know!
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Jimbo,

    Thank you for choosing Photon!

    If you instantiate the networked room object and mark it as DontDestoryOnLoad it will persist between scenes.
  • Jimbo
    Options
    Oh really? I'm guessing I have to do that for every client?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Options
    Yes per client.
  • Jimbo
    Options
    That's working perfectly. Thank you very much!