In the Inspector click the + button and choose “String”
Select the newly added string entry and click the - button
Actual
Unity outputs error:
Could not reach source property name ‘m_Variables.Array.data[0]’ while extracting diffs, the reference does not exist in the source serialized data
using System;
using UnityEngine;
[CreateAssetMenu(fileName = "Repro", menuName = "Test/Create Repro Asset")]
public class Repro : ScriptableObject
{
public MyClass1[] refs = new MyClass1[]
{
new MyClass1()
{
srValue = new MyClass2()
}
};
}
[Serializable]
public class MyClass1
{
[SerializeReference]
public MyClass2 srValue;
}
[Serializable]
public class MyClass2
{
public int value;
}
This repro can also reproduce another bug:
When click “+” button to add a new list element, the newly added element will reference same object instance with previous element, this should not happen. The bug can be reproduce on Unity 2020.3.0f1 and Unity 2021.3.0f1.
That’s by design. SerializeReference allows you to reference the same item and pressing + on a list will copy the previous reference, so its working as expected.
But this Act different from general types in a list. And in this case, it makes no sense to use SerializeReferences in the list(all elements in list references same object). Does Unity has any plan to give developer a way to break this reference?
You can control it with a custom editor or through script. We do this in Localization. I’m not aware of any plans to change this behavior at the moment.