Unable to serialize Gradient when using Odin Polymorphic serialization

Issue #314 resolved
PuzzledBoy
created an issue
  1. Create a script "OdinTest" :
public class OdinTest : SerializedMonoBehaviour
{
    public DataBase data;
}

[Serializable]
public class Data1 :DataBase
{
    public Gradient gradient;
}

public class DataBase{

}
  1. Attach it to a new gameobject,assign a gradient to it.
  2. Get the error :
ArgumentException: Cannot create formatters for a primitive type like GradientMode
Sirenix.Serialization.FormatterLocator.CreateFormatter (System.Type,Sirenix.Serialization.ISerializationPolicy) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Utilities/FormatterLocator.cs:279)
Sirenix.Serialization.FormatterLocator.GetFormatter (System.Type,Sirenix.Serialization.ISerializationPolicy) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Utilities/FormatterLocator.cs:183)
Sirenix.Serialization.ComplexTypeSerializer`1<System.Enum>.WriteValue (string,System.Enum,Sirenix.Serialization.IDataWriter) <0x00c83>
Sirenix.Serialization.Serializer`1<System.Enum>.WriteValue (System.Enum,Sirenix.Serialization.IDataWriter) <0x0005d>
Sirenix.Serialization.GradientFormatter.Write (UnityEngine.Gradient&,Sirenix.Serialization.IDataWriter) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Unity Integration/GradientFormatter.cs:62)
Sirenix.Serialization.MinimalBaseFormatter`1.Serialize (T,Sirenix.Serialization.IDataWriter) <0x00061>
Sirenix.Serialization.MinimalBaseFormatter`1.Sirenix.Serialization.IFormatter.Serialize (object,Sirenix.Serialization.IDataWriter) <0x00101>
Sirenix.Serialization.ComplexTypeSerializer`1<UnityEngine.Gradient>.WriteValue (string,UnityEngine.Gradient,Sirenix.Serialization.IDataWriter) <0x00d19>
(wrapper dynamic-method) object.Dynamic_Write_Data1 (Data1&,Sirenix.Serialization.IDataWriter) <IL 0x00012, 0x0007c>
Sirenix.Serialization.FormatterEmitter/RuntimeEmittedFormatter`1<Data1>.WriteDataEntries (Data1&,Sirenix.Serialization.IDataWriter) <0x0005c>
Sirenix.Serialization.EasyBaseFormatter`1<Data1>.SerializeImplementation (Data1&,Sirenix.Serialization.IDataWriter) <0x0005e>
Sirenix.Serialization.BaseFormatter`1<Data1>.Serialize (Data1,Sirenix.Serialization.IDataWriter) <0x0073b>
UnityEngine.Debug:LogException(Exception)
Sirenix.Serialization.CustomLogger:LogException(Exception) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization.Config/CustomLogger.cs:61)
Sirenix.Serialization.DebugContext:LogException(Exception) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Misc/SerializationConfig.cs:222)
Sirenix.Serialization.BaseFormatter`1:Serialize(Data1, IDataWriter) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Formatters/BaseFormatter.cs:258)
Sirenix.Serialization.BaseFormatter`1:Sirenix.Serialization.IFormatter.Serialize(Object, IDataWriter) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Formatters/BaseFormatter.cs:113)
Sirenix.Serialization.ComplexTypeSerializer`1:WriteValue(String, DataBase, IDataWriter) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Serializers/ComplexTypeSerializer.cs:547)
Sirenix.Serialization.Serializer`1:WriteValueWeak(String, Object, IDataWriter) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Serializers/Serializer.cs:260)
Sirenix.Serialization.UnitySerializationUtility:SerializeUnityObject(Object, IDataWriter, Boolean) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Utilities/UnitySerializationUtility.cs:968)
Sirenix.Serialization.UnitySerializationUtility:SerializeUnityObject(Object, SerializationData&, Boolean, SerializationContext) (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Utilities/UnitySerializationUtility.cs:652)
Sirenix.OdinInspector.SerializedMonoBehaviour:UnityEngine.ISerializationCallbackReceiver.OnBeforeSerialize() (at F:/Sirenix/Sirenix Solution/Sirenix.Serialization/Unity Integration/SerializedMonoBehaviour.cs:31)
UnityEditor.HostView:OnInspectorUpdate()

Related:

Can't serialize Gradient issue : #278

Polymorphic serialization issue : #293

Comments (4)

  1. Log in to comment