- Home /
Can a GameObject be serialized?
Hi All,
I'm writing a custom editor window and have run into serialization issues, namely "Type UnityEngine.GameObject is not marked as Serializable."
The class that contains the GameObject is marked as [Serializable] and I've added [SerializeField] as an attribute to the GameObject public variable and get the error above.
The Unity documentation here says the following:
Your field will only serialize if it is of a type that Unity can serialize:
Serializable types are:
All classed inheriting from UnityEngine.Object, for example Gameobject, Commponent, MonoBehaviour, Texture2D, AnimationClip..
All basic data types like int, string, float, bool.
Some built in types like Vector2, Vector3, Vector4, Quaternion, Matrix4x4, Color, Rect, Layermask..
Arrays of a serializable type
List of a serializable type (new in Unity2.6)
Enums
I'm also getting the same error for other Unity types like Vector3 so I'd really appreciate any information about serialization of basic Unity types. Thanks.
Answer by getyour411 · Sep 03, 2013 at 08:01 AM
You might want to look at this
http://whydoidoit.com/unityserializer/
If you must 'roll your own', you can probably learn from that.
Thanks getyour411, that source is a godsend if I have to go that route, I have read nearly all of whydoidoit's tutorials and can see it helps for Lists, structs and other types but not the Unity types.
To be clear I am trying to use the save/load code by CJCurrie here which uses ISerializer and BinaryFormatter whereas I think the Unity types may only work with XmlSerializer. I'm in over my head now so I may be mixing two types of serialization.
The also ties in with another problem where I can't save my editor window state when the assembly reloads after play/exit is pressed in the editor.
I may have to keep re-reading the Serialization $$anonymous$$ega Post until this sinks in or my head explodes, which ever comes first.