Save System: How do savers on spawned objects work ?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
NotVeryProfessional
Posts: 145
Joined: Mon Nov 23, 2020 6:35 am

Save System: How do savers on spawned objects work ?

Post 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).
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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.)
NotVeryProfessional
Posts: 145
Joined: Mon Nov 23, 2020 6:35 am

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

Post 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.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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.
NotVeryProfessional
Posts: 145
Joined: Mon Nov 23, 2020 6:35 am

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

Post by NotVeryProfessional »

You're probably aware of https://blog.unity.com/technology/spotl ... references which does something interesting in this direction.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Yes. The Dialogue System implements a similar kind of thing for scene events.
Post Reply