Description
The Serialize
method of the GameObject
class is responsible for converting the state of a GameObject
into a JSON representation. This method returns a JsonObject
that contains all the data of the GameObject
. If the GameObject
is an instance of a prefab, the method will return a JSON object that represents the differences (patch/diff) between the instance and the original prefab.
Usage
To use the Serialize
method, call it on an instance of a GameObject
and pass in the desired SerializeOptions
. The method will return a JsonObject
that you can use to inspect or store the state of the GameObject
.
Example
// Example of using the Serialize method
GameObject myGameObject = new GameObject();
Sandbox.GameObject.SerializeOptions options = new Sandbox.GameObject.SerializeOptions();
System.Text.Json.Nodes.JsonObject jsonObject = myGameObject.Serialize(options);
// jsonObject now contains the serialized data of myGameObject