Serializing custom types#

I am trying to serialize a built-in type#

Various other non-primitive types provided by Unity are serializable.
Common examples of these include: UnityEvent, Bounds,
Serializable Unity types should appear in debug mode; look for examples of them appearing in built-in components.

I am trying to serialize my own type#

  1. Custom structs and classes should be marked with the [System.Serializable] attribute.
  2. Ensure that there are serializable types in that structure:

    • References to objects that derive from UnityEngine.Object (a reference to a MonoBehaviour for example) that isn't generic.
    • Primitive data types (such as int, float, double, bool, or string)
    • Enum types.
    • Certain Unity built-in types: Vector2, Vector3, Vector4, Rect, Quaternion, Matrix4x4, Color, Color32, LayerMask, AnimationCurve, Gradient, RectOffset, GUIStyle.
      marked with the [SerializeField] attribute, or are public.

    Empty structures or those without serializable fields are also not serializable.

  3. Don't mark your classes, structs, or fields with abstract, static, const, or readonly.