Serializing GameObjects?
jeffsim opened this issue · comments
I'm trying to compose a GameObject at runtime and then serialize it, but am failing. Is this not supported?
Here's a simple repro; attach this to an empty game object in a scene and run it:
public class TestComponent : SerializedMonoBehaviour
{
public int testValue = 100;
}
public class TestScript : MonoBehaviour
{
void Start()
{
var go = new GameObject();
go.AddComponent<TestComponent>();
byte[] bytes = SerializationUtility.SerializeValue(go, DataFormat.JSON);
File.WriteAllBytes("testOutput", bytes);
/* Contents of 'testOutput' file after running the above:
{
"$id": 0,
"$type": "0|UnityEngine.GameObject, UnityEngine.CoreModule"
}
*/
}
}
I was expecting to see 'TestComponent' in the testOutput file. I just purchased OdinInspector so am still trying to orient myself on what is/isn't expected to work wrt persisting composed GOs.
Thanks,
Jeff
This is indeed not supported by Odin, and will likely never be unless Unity rewrites their asset system - only Unity is able to serialize its own objects down to a file, as Unity does not provide the asset API necessary to do it. All Odin can do is store extra data in a Unity object, and use that to reconstruct complex types that it serialized, when Unity is deserializing the object.