AOTSupportScanner ignores Odin-serialized ISerializationCallbackReceivers when serialized by SerializeReference attribute

Issue #755 new
creativitRy created an issue

public class RefTest : SerializedScriptableObject
    public object Value = new RefSerialized();

    public class RefSerialized : ISerializationCallbackReceiver
        public HashSet<int> Value;

        private byte[] _serializationData;

        void ISerializationCallbackReceiver.OnBeforeSerialize()
            _serializationData = SerializationUtility.SerializeValue(Value, DataFormat.Binary);

        void ISerializationCallbackReceiver.OnAfterDeserialize()
            Value = SerializationUtility.DeserializeValue<HashSet<int>>(_serializationData, DataFormat.Binary);

What happened?

Under Odin Preferences > AOT Generation (or during build), the Scan Project button does not fully detect necessary Types:

When a field is marked with the [SerializeReference] attribute, Odin does not look at the value during AOT scanning. This results in it missing Types that it needs to codegen for IL2CPP stripping.

How can we reproduce it?

  1. Take the provided code and create the RefTest ScriptableObject in a Resources folder.
  2. Attempt AOT Generation Scan Project.
  3. Notice that the type HashSet<int> was not added to the list of serialized Types.

Note that the issue happens regardless of whether RefTest derives ScriptableObject or SerializedScriptableObject.

What version of Unity are you using? What version of Odin are you using? (See "Tools > Odin Inspector > About")

Tested with two versions:

  • Unity 2020.1.3f1 with Odin 2.1.12
  • Unity 2020.1.6f1 with Odin 3.0.3

Do you have Editor Only mode enabled?


What operating system are you on?

Windows 10 Pro

I think this issue can be solved by first getting all SerializeReference FieldInfos using UnityEditor.TypeCache.GetFieldsWithAttribute<SerializeReference>, and then scanning for all objects of the declared types. I would really appreciate it if you also backport this fix to Odin 2.1.x, please. Thank you in advance!

Comments (0)

  1. Log in to comment