SerializedProperty becomes invalid in some scenarios when using SerializeReference

I ran in to this issue when working with bindings in UI Elements but it seems to be a core problem that only causes problems in UI Elements. The behavior is the same in 2019.3.0f1 and 2020.1.0a15.

The SerializedProperty for a child field of a ManagedReference will become invalid (i.e the internal isValid property returns false) when the owning object has only a single reference saved. Adding a second reference (even if it is null) fixes the problem. This manifests as an issue when attempting to bind to the property in UI Elements - the binding is created properly but is cleared the first time it is updated.

A sample project is attached showing the working and failing cases.

5268330–527313–Reference Test.zip (24 KB)

Hi! Please report a bug through our Bug Reported which you can find in Help → Report a Bug.

You can find out more about bug reporting here: https://unity3d.com/unity/qa/bug-reporting

Is there some information about this bug?

I’ve got very simular problem, so any information will be very helpful.

I submitted the bug report with the same information I posted here but haven’t heard anything about it yet. I have run in to a bunch of other oddities with managed reference serialized properties so I moved on for now. I’ll probably be getting back to this sometime next week so if I figure anything else out I’ll post back here.

I’m not sure on this since most of the SerializedProperty implementation is internal but it seems like most of the issues stem from Unity re-instantiating managed references every time an object is updated from it’s SerializedObject. This then invalidates any SerializedProperty that has been stored (like those used in UI Elements binding) presumably because it is some kind of weak reference.