Multiplayer and changing scenes

Started by Daryl Winters 6 posts 508 views

Reply on sbox.game
  1. edited Mar 2025 #1
    Daryl Winters 2,065
    Hi everyone,

    I'm working on a multiplayer game project and I'm looking for some advice on how to manage data persistence between scenes. Here's a breakdown of what I'm trying to achieve:

    So, first, some context, I have two main scenes: a lobby scene where players can choose their loadouts, roles, and select levels, and a main game scene where the actual gameplay happens.
      This thing is, I need to persist certain information (like player choices) between these scenes.


     Right now, there's no system in place that outlives a scene. Game objects and gameobjectsystems are tied to the scene's lifetime.
     I'm aware of the `DontDestroyOnLoad` flag, but it feels a bit hacky and I'm not sure if it's the best approach for a clean architecture.

    So
       - What are some good patterns or best practices to achieve data persistence between scenes in a multiplayer game? / How would you handle the transition of player data from the lobby to the main game scene?

    And 
       - If I want the persisting information to be networked, how should I approach this?
       - Does the `DontDestroyOnLoad` method handle networked data, or are there better alternatives?

    I'd appreciate any insights or experiences you can share. Thanks in advance for your help!
  2. #2
    Trundler 996
    If you don't wanna use DontDestroyOnLoad, then you clearly need to persist the player's choices to the file or some external server. Serialize the information you need to JSON, and then deserialize on scene switch.
  3. #3
    Daryl Winters Started this 2,065
    Yes, that can do the trick
    Still a bit sad there's no System tied to game lifetime 
  4. #4
    k0fe 318
    Alternatively you can use GameResource to change data in there. But it would same as a JSON, just with an in engine editor

    https://sbox.game/dev/doc/assetsresources/gameresource-extensions/

  5. #5
    Unknown
  6. #6
    Bubbies 1,370
    GameObjectSystem ? Il me semble qu'ils persistent après un chargement de scène