Practical way to work across scenes without duplication?

So I’ve sort of got the ball rolling here and I have a working inventory, turn based battle system, animations etc.

I’m now starting to think in the long run as I have a couple of scenes I like to call “levels” of my game. How would I “save” data from level 1 and transfer it to level 2?

Currently I have to copy the whole hierarchy “except the objects unique to the level” such as HUD, Main Characters, and Inventory.

But when the game is “running” and a new level loads, how would I transfer the data?? such as Player stats? Items in Inventory? etc.

some options:

That sounds like a job for DontDestroyOnLoad. :slight_smile:
There are other options for moving data between scenes, but to re-use the same objects, I think this method is often the best.
Ah, you got another response as I was writing.

I get that you can Load certain objects on Load, but when you are working on level 2, you need those objects right? So the practical way is to copy and paste them from level one. Because OnLevelLoad only happens while the game is “running”. So then I would have to delete the “copies” after I’m done making the level?

prefabs scare me… I think the best way is to just make the levels while reusing the same GO’s like methos5k said, and then deleting the ones you will load, such as “players and HUDs”.

But I have a lot more work to do before I have to worry about loading! I just wanted to make sure it was practical enough and things to keep an eye out for in case of loading in the future.

Sidenote: Scripting in Unity is just like the game i’m creating in it. A dark dungeon with so many mysteries.

Reusing objects in different scenes then prefabs are the way to go. Just drag the object from once scene into a folder named prefabs in assets and the drag it out again. There is nothing to be scared off.

By using a prefab you can save loads of time. Say for example you have 100+ of the same object across multiple scenes. Let’s say a platform you character stands on and then you realise later on that the collider isn’t in right place. You only need to edit the prefab and that change is automatically applied to all the prefabs in every scene.

If you need one or two to be different in a couple of scenes, then you can drag it in and break the prefab instance.

I agree that prefabs are very important.
And an obvious note, prefabs and DontDestroyOnLoad (as it pertains to this topic/question) aren’t mutually-exclusive. :slight_smile: