Class SceneSerialization
Used to save and load scene objects in a JSON format
Namespace: Unity.RuntimeSceneSerialization
Syntax
public static class SceneSerialization
Methods
FromJson<T>(String)
Alternative version of JsonSerialization.FromJson which uses JsonSceneReader
Declaration
public static T FromJson<T>(string jsonString)
Parameters
Type | Name | Description |
---|---|---|
String | jsonString | The Json string to be deserialized |
Returns
Type | Description |
---|---|
T | The deserialized value |
Type Parameters
Name | Description |
---|---|
T | The type of value represented by the Json string |
Exceptions
Type | Condition |
---|---|
Exception | Thrown if serialization failed |
FromJsonOverride<T>(String, ref T)
Alternative version of JsonSerialization.FromJson which uses JsonSceneReader
Declaration
public static void FromJsonOverride<T>(string jsonString, ref T value)
Parameters
Type | Name | Description |
---|---|---|
String | jsonString | The Json string to be deserialized |
T | value | A reference of type T to use for populating the deserialized value |
Type Parameters
Name | Description |
---|---|
T | The type of value represented by the Json string |
Exceptions
Type | Condition |
---|---|
Exception | Thrown if serialization failed |
ImportScene(String, AssetPack, Action<List<GameObject>>)
Load a scene from JSON into the active scene
Declaration
public static SerializationMetadata ImportScene(string json, AssetPack assetPack = null, Action<List<GameObject>> onAfterDeserialize = null)
Parameters
Type | Name | Description |
---|---|---|
String | json | JSON representation of this scene |
AssetPack | assetPack | The AssetPack to be used for asset references |
Action<List<GameObject>> | onAfterDeserialize | An action which will be invoked after deserialization before root objects are activated |
Returns
Type | Description |
---|---|
SerializationMetadata | The SerializationMetadata used to import this scene |
RegisterPropertyBag(Type)
Register a reflected property bag which is compatible with scene serialization for the given type
Declaration
public static void RegisterPropertyBag(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type which will be represented by the property bag |
RegisterPropertyBagRecursively(Type)
Register a reflected property bag which is compatible with scene serialization for the given type and the types of its properties, and their properties recursively
Declaration
public static void RegisterPropertyBagRecursively(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type which will used to create the property bags |
SerializeScene(Scene, SerializedRenderSettings, AssetPack)
Serialize a scene to Json Scene must be loaded and valid
Declaration
public static string SerializeScene(Scene scene, SerializedRenderSettings renderSettings = null, AssetPack assetPack = null)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | The scene to serialize |
SerializedRenderSettings | renderSettings | The scene's render settings |
AssetPack | assetPack | The asset pack used to store and retrieve assets |
Returns
Type | Description |
---|---|
String | The serialized scene as a Json string |
ToJson<T>(T, SerializationMetadata)
Alternative method to JsonSerialization.ToJson which uses JsonSceneWriter
Use this if you need to support ISerializationCallbacks
Declaration
public static string ToJson<T>(T value, SerializationMetadata metadata = null)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to serialize |
SerializationMetadata | metadata | SerializationMetadata for this call |
Returns
Type | Description |
---|---|
String | A string containing the Json serialized representation of |
Type Parameters
Name | Description |
---|---|
T | The type of the value being serialized |