Page 1 of 1

Save System: How do savers on spawned objects work ?

Posted: Sat Nov 27, 2021 2:18 am
by NotVeryProfessional
I don't understand how savers on spawned objects (managed throught SpawnedObjectManager and SpawnedObject) are supposed to work.

The SpawnedObjectManager records this data: prefabName, position, rotation

The SpawnedObject itself records no data, it only registers/unregisters with the SpawnedObjectManager


I don't see how savers on the spawned object get their save data. I can't assign a key to the saver in the prefab, obviously, as it would be the same across all instances. I likewise can't leave it empty so it uses the gameObject name because again there's no guarantee that that's unique. The SpawnedObjectManager doesn't save any keys from any savers - so how?

Additionally, I have a number of spawned objects that start existing in the level, but can be destroyed by the player. This part appears to work (i.e. when I load a game, they correctly don't exist).

Re: Save System: How do savers on spawned objects work ?

Posted: Sat Nov 27, 2021 8:10 am
by Tony Li
Hi,

Savers on spawned objects only work if you're spawning unique objects -- for example, randomly spawning two out of five unique boss NPCs for a boss fight.

In version 2.2.24, I can look into saving data on other spawned objects, too. (Work on 2.2.23 is wrapping up now.)

Re: Save System: How do savers on spawned objects work ?

Posted: Sat Nov 27, 2021 12:09 pm
by NotVeryProfessional
That explains why I didn't get it to work. I was trying to assign a unique key to each object using System.Guid but that resulted only in strange behavior.

I'll write my own saver in that case, and share it here for others.

Re: Save System: How do savers on spawned objects work ?

Posted: Sat Nov 27, 2021 1:36 pm
by Tony Li
Sounds good.

My plan for 2.2.24 is to associate a unique System.Guid with each SpawnedObject's saver data so it can pull its saver data from the saved game data.

Re: Save System: How do savers on spawned objects work ?

Posted: Sat Nov 27, 2021 2:12 pm
by NotVeryProfessional
You're probably aware of https://blog.unity.com/technology/spotl ... references which does something interesting in this direction.

Re: Save System: How do savers on spawned objects work ?

Posted: Sat Nov 27, 2021 2:34 pm
by Tony Li
Yes. The Dialogue System implements a similar kind of thing for scene events.