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.

You might want to look at this

http://whydoidoit.com/unityserializer/

If you must ‘roll your own’, you can probably learn from that.