Managing Data Between Scenes and Scalability

Hi,

I’ve been trying to find a way to save data between scenes (as in like 30 scenes!).

(I kind of had this vision in mind like Legend of the Golden Robot with a shop, then player customization, and battles where the player stats are changed, etc…)

I’ve been looking into resources online on saving data, and am kinda overwhelmed with all the possibilities!

// Data Persistence (unity training session)

https://gamedev.stackexchange.com/questions/110958/what-is-the-proper-way-to-handle-data-between-scenes/141060#141060
(of which I thought dependency injections with Zenject seemed interesting).

I originally toyed around a bit with static variables which is not at all scalable to over 30 scenes – not quite sure how scalable static classes are to save data either…

I’ve never used Zenject before and don’t have much experience with dependency injections – I want to see what other ways there are to manage data between scenes before going all in.

Any ideas on some ways to save data for a large project (like an RPG game)?
It’s overwhelming keeping track of so many different things – player stats, and their progress throughout various levels-- on that note, any recommendations for saving the progress in a scene like if a player destroys all the boxes in the scene and then exits when he renters that scene the boxes will stay destroyed)

Thank you. Cheers!

Zenject won’t help you. You need some kind of persistent data storage.

Check out some Youtube tutorials on load/save games. Generally there are a few levels of data persistence:

  1. only persists in the current scene, can go away (just use regular old member variables for this)

  2. must persist from one scene to the next (such as “what door did I go into so I come back out of it?”, broken debris from crates, etc.)

  3. must persist through the entire game (xp, health, inventory)

  4. must be saved to disk if I save my game. (probably not debris from crates, but up to you)

  5. overall metagame stuff, like “did I unlock this bonus character” and “how many orcs have I slain in my life?”

Obviously you can put everything into one bucket if you like but it gets inefficient space-wise.

I would recommend a JSON-based approach (turns your object hierarchy into text) because the data will be saved as a text file, letting you edit and view it in order to debug your code as you go.

If you want Dictionaries and other useful data structures, do NOT use the build-in Unity “tiny JSON,” as that won’t handle Dictionaries and is very brittle and aimed towards performance rather than broad data usefulness.

Instead, reach for the asset store free JSON .NET package. WAY better system.

In any case, start a series of objects that go into each other, keeping in mind the categories above, and start your code transacting with them. That’s the hard part: when do I read this stuff, when do I convert it into visible UI items for inventory? when do I put it back, etc.

Only later do you need to worry about actually reading/writing it to disk. But take it a few fields at a time, like just save the gold first, get used to that, etc. Don’t make 256,000 variables and try to get them all hooked up. Hooking up a single value will give you a TON of insight.

1 Like