Serialization issue with AnimationCurves (MM 1.9.7, Unity 2018.3)
Multiple (identical) instances of AnimationCurve are serialized to the same value -> only one instance present after deserialization.
Somewhere between Unity 5.6 and 2018.3 the implementation of AnimationCurve has changed and seems to cause problem in CustomSerialization so that multiple instances are bound to the same link.
The problem is here: CustomSerialization.cs:L97
//cheking if this object was already saved
if (references.Contains(obj)) return references.IndexOf(obj);
In serialized form you can see that two different CurveGenerators (at index 1 & 7) link to the same AnimationCurve (link=2).
serializedVersion: 197
classes:
- ...
- "<MapMagic.CurveGenerator>\r\n\t<curve type=UnityEngine.AnimationCurve link=2/>\r\n\t<extended
type=System.Boolean value=True/>\r\n\t<min type=UnityEngine.Vector2 x=0 y=0/>\r\n\t<max
type=UnityEngine.Vector2 x=1 y=1/>\r\n\t<input type=MapMagic.Generator+Input link=4/>\r\n\t<maskIn
type=MapMagic.Generator+Input link=5/>\r\n\t<output type=MapMagic.Generator+Output
link=6/>\r\n\t<enabled type=System.Boolean value=True/>\r\n\t<mandatory type=System.Boolean
value=False/>\r\n\t<guiRect type=UnityEngine.Rect x=529 y=93 width=160 height=120/>\r\n</MapMagic.CurveGenerator>\r\n"
- "<UnityEngine.AnimationCurve>\r\n\t<keys type=UnityEngine.Keyframe[] link=3/>\r\n\t<preWrapMode
type=UnityEngine.WrapMode value=8/>\r\n\t<postWrapMode type=UnityEngine.WrapMode
value=8/>\r\n</UnityEngine.AnimationCurve>\r\n"
- ...
- ...
- ...
- ...
- "<MapMagic.CurveGenerator>\r\n\t<curve type=UnityEngine.AnimationCurve link=2/>\r\n\t<extended
type=System.Boolean value=True/>\r\n\t<min type=UnityEngine.Vector2 x=0 y=0/>\r\n\t<max
type=UnityEngine.Vector2 x=1 y=1/>\r\n\t<input type=MapMagic.Generator+Input link=8/>\r\n\t<maskIn
type=MapMagic.Generator+Input link=9/>\r\n\t<output type=MapMagic.Generator+Output
link=10/>\r\n\t<enabled type=System.Boolean value=True/>\r\n\t<mandatory type=System.Boolean
value=False/>\r\n\t<guiRect type=UnityEngine.Rect x=728 y=89 width=160 height=120/>\r\n</MapMagic.CurveGenerator>\r\n"
Steps to reproduce (with Unity 2018.3):
- Create empty scene with only two CurveGenerators
- Save scene and reload
- Change one curve and the other changes as well
Expected result: AnimationCurves stay separated
Actual result: AnimationCurves are falsely reused