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!

  • \$\begingroup\$ Can you give us some examples of the specific configuration changes you want to save & transmit? Different types of variation might need different techniques. \$\endgroup\$ – DMGregory Jun 6 '18 at 10:27
  • \$\begingroup\$ @DMGregory For example: I have a character customisation system that customises the characters, their weapons (e.g. sights, butt stocks etc.), equipment (e.g. colour, different vests, helmets etc.) or uses defaults. Before a player starts a game session, he picks characters and the session should load the characters with all of their stuff (either default or customised). That's the idea. \$\endgroup\$ – JDoeBloke Jun 6 '18 at 10:48
  • \$\begingroup\$ No, that part was clear. I mean how those configurations are represented in your internal data structures. Are they parts parented in an object hierarchy? Mesh swaps? Prefab swaps? Components added/removed dynamically? Inspector parameters? Custom data structs? etc. There are a lot of ways to skin that cat, and not necessarily one stand-out "BEST" way. ;) \$\endgroup\$ – DMGregory Jun 6 '18 at 11:03
  • \$\begingroup\$ @DMGregory Object Hierarchy mostly and sometimes objects are added or removed at runtime by "modifying" prefabs. E.g. characters and weapons are prefabs that are added or replaced (selected) at runtime but they're taken from the list of Weapons class objects that is in the Character class. \$\endgroup\$ – JDoeBloke Jun 6 '18 at 11:15

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.

  • \$\begingroup\$ Thanks so much for the tip. There's another issue though. How would I proceed with the objects themselves. I mean how to form a character with gear and weapons and passing them to the scene or database or whatever...How to customize them? I know the "hard way" by writting a class that would replace parts of objets and characters through scripts, but that's it. How would you make a customizable characters and weapons? \$\endgroup\$ – JDoeBloke Jun 12 '18 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.