Saving Game Objects

Optionally save information about spawned prefabs or placed game objects in your scenes.

This information can be saved and restored between scene changes and in save games.

There’s a difference between saving spawned prefabs and game objects already placed in your scenes. Spawned prefabs use Prefab Savers, placed game objects use Game Object Savers.

Saving Content #

Both Prefab Savers and Game Object Savers can save the same content and are saved/loaded similarly. The following information applies to both of them.

What is saved? #

Both prefab savers and game object savers can save the same content:

  • position
  • rotation
  • scale
  • local variables

You can also save this information for all child objects of the saved game object.

Additionally, any component attached to the game object (and it’s child objects) implementing the IComponentSaveData interface will be saved as well. See this documentation for more details.

When is it saved? #

A game object’s data is saved when it is destroyed. This also includes when it’s destroyed by changing scenes.

If the data is also saved with save games, all (saving) game objects of the current scene will store their data as well.

When is it loaded? #

The data is loaded when the scene is loaded.

Save Games #

To save prefab saver or game object saver data with save games, you need to set up saving them in UI > Save Game Settings. You can save the data from all scenes or only the current scene – and automatically remove data from a scene after a defined number of scene changes (without returning to the scene).

Prefab Savers #

Prefab savers are used to store information of spawned prefab instances. Saved prefab instances will be respawned and load the stored data when the scene is loaded.

Prefab savers are set up in Base/Control > Prefab Savers. To be able to save information about a spawned prefab, it must match one of the set up prefab saver’s prefab.

Adding Prefabs Instances #

Prefab instances need to be added to the prefab savers in order to save them.

This is done in the Spawn Prefab node in schematics, by enabling the Add Prefab Saver setting. This setting is disabled by default, not using prefab savers.

Prefab instances that are added to a prefab saver will save their content when they are destroyed, i.e. also when changing scenes.

Removing Prefab Instances #

Destroying the prefab instance will save it’s content, respawning it when the player reloads the scene.

To prevent this, the Destroy Prefab and Destroy Object nodes in schematics have the Remove Prefab Saver setting. This setting is enabled by default, removing the destroyed game object from prefab savers.

You can also remove an instance without destroying it using the Remove From Prefab Saver node. Beside removing a single instance, it can also remove all instances of a prefab saver, or all prefab savers in the scene.

The Clear Prefab Savers node can remove all prefab data from a scene or all scene.

Game Object Savers #

Game object savers are used to store information of game objects already placed in your scene’s setup, i.e. not spawned during play. Their information will be restored when the scene is loaded.

They’re only used to save/load information like position or component data – they don’t handle enabling/disabling or destroying a game object. For this, use e.g. a Game Object Manager component to enable/disable a game object based on defined conditions.

Game Object Saver Component #

To save a game object’s information, add a Game Object Saver component.

The different game objects are identified by their Scene GUID, defined in the component. A random GUID is generated when the component is added. If two game objects use the same GUID, they’ll also share the data.

When the component’s game object is destroyed (also when changing scenes), the content will be saved.

When loading a scene, the component will get it’s data based on the Scene GUID, loading the stored information (e.g. position).

Removing Game Object Saver Data #

Unlike prefab savers, game object savers can’t be added or removed. If a game object of your scene setup uses it, it’ll keep using it.

However, you can use the Clear Game Object Savers node in schematics to remove the game object saver data from a scene or all scenes.