Limitations
Unity Object Reference uses ILPostProcessing to transform interface fields into serializable UnityObjectReference<T> fields. There are currently a few limitations to be aware of.
Private fields only
Section titled “Private fields only”Currently, only private fields are processed.
The ILPostProcessor cannot guarantee that it will run on every assembly involved in a project. If a field has higher accessibility, such as internal, protected, or public, code in an assembly that was not processed could potentially access the field without accounting for the field type change to UnityObjectReference<T>.
Higher-accessibility fields are therefore unsupported. A warning is written to the Unity Console and the field is skipped.
Recommendation
Section titled “Recommendation”The recommended approach is to keep the serialized field private and expose it through a property when external access is required.
[SerializeField]private IPlayerCueInputProvider _inputProvider;
public IPlayerCueInputProvider InputProvider => _inputProvider;Arrays and collections
Section titled “Arrays and collections”Arrays and collections are not currently supported.
This includes interface fields such as:
[SerializeField]private IInterface[] _interfaces;and collection types such as:
[SerializeField]private List<IInterface> _interfaces;These fields are currently skipped by the ILPostProcessor.
Support for arrays and collections may be added in a future version, but they will come with their own limiations.
Types such as
List<IInterface>will becomeList<UnityObjectReference<IInterface>>, which introduces usages which will be very complex to weave with ILPostProcessing
Recommendation
Section titled “Recommendation”The recommended approach is to use the explicity UnityObjectReference<T> type directly:
[SerializeField]private IPlayerCueInputProvider _inputProvider;
public IPlayerCueInputProvider InputProvider => _inputProvider;