Pass and Change Objects Between Scenes in Unity

I ran into a bit of a problem with organasing object changes as well as storing them and passing to scenes. By that, I mean that I'm programming a game that has different characters and possibility to customize them as well as their equipment and weapons. It's gonna be a multiplayer game...so, the question is what's the BEST practice of storing and passing customized characters with weapons between scenes and via network connection?

Similarly to Rainbow Six Siege, where all your custom stuff is saved on a user and passed both in single and multiplayer modes into a level.

Just need some refs, tips or maybe articles on the matter. No code needed. Thanks in advance!

Answers 1

  • If you are just looking for a pointer in the right direction, I would suggest reading about SyncVars. I would be tempted to suggest using scriptable objects, but I read that they have problems in multiplayer games where data needs to be synced with the server.

    As far as I know, the "best practice" for this would depend completely on how you choose to model client-server interactions. If you plan to have data stores for character information hosted locally on the machine, it may be best to simply create a configuration file, and then pass that data into a class that syncs each attribute with the server using SyncVars. I would avoid using PlayerPrefs for this if you care about the data being secure from manipulation, and instead find a way to write the data in some encrypted form using a key that is stored server-side.

    If you are hosting all the player data on the server, you may want to look into implementing some kind of database model external from your code and developing a manager class that collects data via queries on player id's as they log in and connect to a session. If you are worried about cheating this would be the route I would go. If you want to go the SQL route, many people use MySQL with Unity projects requiring databases, otherwise MongoDB may be a good option for you.

    Regardless of which of the above options you use, you will likely either need to store data about players between sessions either locally in an a DontDestroyOnLoad class or classes between scenes and access this data that way, or sync the data with the server between scenes, load the new scene, and then get the synced data about the player back from the server on scene load and re-instantiate the players object and data.


Related Questions