I want to create a custom attribute for serialize an interface to the inspector. So far, I already show the object field with type of interface to the inspector, but if I drag and drop a component to that field I got an error that say “InvalidOperationException: Cannot assign an object deriving from UnityEngine.Object to a managed reference. This is not supported”. Anyone know how to solve this problem?
You cannot solve this problem. Interfaces cannot be dragged onto Inspector references.
Instead, make a base class that implements the interface, or just rely on the base class. And add the [SerializeReference] attribute to the field, otherwise deserialization will fail.
Thanks for the clarifications!
Clearly I haven’t used any of these often enough and I tend to think that’s because there is always an alternative that just plays better with Unity and still works well.