Search Unity

Serializing Color, Vector3, Quaternion not working despite documentation

Discussion in 'Editor & General Support' started by DreamPower, Jul 3, 2021.

  1. DreamPower

    DreamPower

    Joined:
    Apr 2, 2017
    Posts:
    103
    Unity documentation says this:
    https://docs.unity3d.com/Manual/script-Serialization.html

    However, when I try to serialize those types, I get this error:
    SerializationException: Type 'UnityEngine.Color' in Assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

    This is when I define a class as System.Serializable and have a field in it:
    [SerializeField]
    public Color[] colors;

    And then call BinaryFormatter.Serialize. I found another person who had the same issue: https://answers.unity.com/questions/1645980/cant-serialize-color-or-vector2.html (their answer was just, don't do it, serialize each float manually...but the documentation says it should work without that).
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909