Saving dontdestroyonload object

Any good advice about saving the objects that we are carrying between scenes? So if we have an object in the starting scene, and then we move to other scenes, when we save progress then, how do we tell it to store that dontdestroyonload object. Cause my logic is it will load from that scene where we have saved, and this object is not originally from there… so it won’t automatically load it. I’ve also am wondering how to tell it to save and load from a particular scene, but I guess that can be another thread :).

You can make a prefab for this object. Then, in the scene you must check if the object exists. If it doesn’t, instantiate its prefab. Of course, if there are some unique parameters in the prefab, you have to save them before leaving the game session and put the back on load.

1 Like

Oh, OK, that’s interesting, I’ll look into instantiating the prefabs. Thanks.

But just, what do you mean by ‘’…put the back on load’'?

I meant put them back on load. Put unique properties of the object back when the game is loaded.

Oh, thanx :smile:…

So, this means that we can make changes to the prefab, and save those… all during gameplay?

No, I do not think that it is possible to save the changes of the prefabs in such way that you will be able to instantiate it later with this data. However, you can save the data somewhere else: PlayerPrefs or XML. It depends on the type of data that the prefab contains. And, afterwards, when the prefab is instantiated, load this data and apply it to the object/prefab on the scene.

1 Like

Oh, that makes sense… thanx for all the info, that was helpfull :smile:. If something else comes to mind, I’ll ask you here again…

1 Like