Next: , Previous: , Up: Serialization   [Contents][Index]


15.2 Scene Object List Serializer

Component: SceneObjectListSerializer

Scene Object List Serializer allows the player to save the contents of a scene. It saves position, rotation, scale, and material list. The objects you are loading, and their materials, must be directly inside a folder called ’Resources’ anywhere in your project, or Unity will not have access to the data.

To use, add a tag to your game for objects that you want to save. Then, at save time, call ’PopulateByTag’ for each tag of objects you want to save. If saving more than one tag, disable ’Auto Save On Populate’ and call ’Save’ after all tags are added. To load, first call ’Clear’ to clear the temporary object list then ’ClearObjectsByTag’ for each tag you wish to load to remove the physical objects from the scene, then call ’Load’ to get the old temporary object list from disk and put it into memory, if ’Auto Instantiate’ is disabled, call ’InstantiateObjectList’ when done loading tags.

Field of SceneObjectListSerializer: bool autoInstantiate

Do we want to automatically instantiate the objects when we load?

Default value: true

Field of SceneObjectListSerializer: bool autoSaveOnPopulate

Do we want to save automatically when we gather a list of objects from the scene? (recommended)

Default value: true

Field of SceneObjectListSerializer: bool localBackup

When saving to URL, should we save the file locally as well?

Default value: false

Debugging and Help

Field of SceneObjectListSerializer: List<SceneObject> objects

The list of local objects stored in memory. Shown here for debugging purposes, calling ’Save’ will write this object list to disk, and ’Load’ will get the object from disk and ADD it to the current list. ’Clear’ can be used to clear the list and start again.

Default value: new List<SceneObject>()

Message on SceneObjectListSerializer: Clear ()

Clears the object list. This is a list stored in temporary memory that you can save to disk with ’Save’ or add objects to with ’PopulateByTag’

Message on SceneObjectListSerializer: PopulateByTag (string)

Adds objects currently in the scene, defined by the tag supplied as a parameter, to the object list for saving. Call this multiple times to add multiple sets of objects to the list, but only if you’ve disabled ’Auto Save On Populate’ in which cas you need to call ’Save’ when you’re done.

Argument: The tag representing objects we want to add to the list for saving to disk.

Message on SceneObjectListSerializer: Save ()

Saves the current object list to disk. Make sure to call ’PopulateByTag’ before calling this, otherwise the list may be empty.

Message on SceneObjectListSerializer: ClearObjectsByTag (string)

Deletes all objects with a supplied tag from the scene. Be sure to do this before loading objects or you will get duplicates.

Argument: A Tag representing the scene objects you want to delete. Usually this is the same as the tag for objects you are loading. To clear multiple tags, call this multiple times (try using a ’Message Relay’).

Message on SceneObjectListSerializer: Load ()

Attempts to load the current level from disk. If ’Auto Instantiate’ is enabled, this will also cause the objects to be instantiated after loading.

Message on SceneObjectListSerializer: InstantiateObjectList ()

Instantiates the current object list into the game. Useful if not using ’Auto Instantiate’ but be sure to call ’ClearObjectsByTag’ first, to get rid of the old ones.

Message on SceneObjectListSerializer: SetUniqueIdentifier (string)

Assigns an optional unique name to this file. Change this to save/load a separate save file for the same scene.

Argument: Name of the unique save file identifier for this file.

Message on SceneObjectListSerializer: SaveToUrl (string)

Saves the current object list to a web server. You will need some server-side code to handle this (Node.js recommended)

Argument: The URL for the POST request.

Message on SceneObjectListSerializer: LoadFromUrl (string)

Loads a new object list from a web server. You will need some server-side code to handle this (Node.js recommended)

Argument: The URL for the GET request.

Message on SceneObjectListSerializer: SetUsername (string)

Assigns a username, must be called before saving/loading to a URL

Argument: The new user name for the web request

Field of SceneObjectListSerializer: bool autoInstantiate

Do we want to automatically instantiate the objects when we load?

Default value: true

Field of SceneObjectListSerializer: bool autoSaveOnPopulate

Do we want to save automatically when we gather a list of objects from the scene? (recommended)

Default value: true

Field of SceneObjectListSerializer: bool localBackup

When saving to URL, should we save the file locally as well?

Default value: false

Debugging and Help

Field of SceneObjectListSerializer: List<SceneObject> objects

The list of local objects stored in memory. Shown here for debugging purposes, calling ’Save’ will write this object list to disk, and ’Load’ will get the object from disk and ADD it to the current list. ’Clear’ can be used to clear the list and start again.

Default value: new List<SceneObject>()

Message on SceneObjectListSerializer: Clear ()

Clears the object list. This is a list stored in temporary memory that you can save to disk with ’Save’ or add objects to with ’PopulateByTag’

Message on SceneObjectListSerializer: PopulateByTag (string)

Adds objects currently in the scene, defined by the tag supplied as a parameter, to the object list for saving. Call this multiple times to add multiple sets of objects to the list, but only if you’ve disabled ’Auto Save On Populate’ in which cas you need to call ’Save’ when you’re done.

Argument: The tag representing objects we want to add to the list for saving to disk.

Message on SceneObjectListSerializer: Save ()

Saves the current object list to disk. Make sure to call ’PopulateByTag’ before calling this, otherwise the list may be empty.

Message on SceneObjectListSerializer: ClearObjectsByTag (string)

Deletes all objects with a supplied tag from the scene. Be sure to do this before loading objects or you will get duplicates.

Argument: A Tag representing the scene objects you want to delete. Usually this is the same as the tag for objects you are loading. To clear multiple tags, call this multiple times (try using a ’Message Relay’).

Message on SceneObjectListSerializer: Load ()

Attempts to load the current level from disk. If ’Auto Instantiate’ is enabled, this will also cause the objects to be instantiated after loading.

Message on SceneObjectListSerializer: InstantiateObjectList ()

Instantiates the current object list into the game. Useful if not using ’Auto Instantiate’ but be sure to call ’ClearObjectsByTag’ first, to get rid of the old ones.

Message on SceneObjectListSerializer: SetUniqueIdentifier (string)

Assigns an optional unique name to this file. Change this to save/load a separate save file for the same scene.

Argument: Name of the unique save file identifier for this file.

Message on SceneObjectListSerializer: SaveToUrl (string)

Saves the current object list to a web server. You will need some server-side code to handle this (Node.js recommended)

Argument: The URL for the POST request.

Message on SceneObjectListSerializer: LoadFromUrl (string)

Loads a new object list from a web server. You will need some server-side code to handle this (Node.js recommended)

Argument: The URL for the GET request.

Message on SceneObjectListSerializer: SetUsername (string)

Assigns a username, must be called before saving/loading to a URL

Argument: The new user name for the web request


Next: , Previous: , Up: Serialization   [Contents][Index]