Version 3.0.0.2

Odin has a dedicated attribute overview with examples

OnInspectorDisposeAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = true, Inherited = false)]
[Conditional("UNITY_EDITOR")]
public class OnInspectorDisposeAttribute : Attribute, _Attribute

The OnInspectorDispose attribute takes in an action string as an argument (typically the name of a method to be invoked, or an expression to be executed), and executes that action when the property's drawers are disposed in the inspector.

Disposing will happen at least once, when the inspector changes selection or the property tree is collected by the garbage collector, but may also happen several times before that, most often when the type of a polymorphic property changes and it refreshes its drawer setup and recreates all its children, disposing of the old setup and children.

Inheritance
  • System.Object
  • System.Attribute
  • OnInspectorDisposeAttribute
Example

The following example demonstrates how OnInspectorDispose works.

public class MyComponent : MonoBehaviour
{
    [OnInspectorDispose(@"@UnityEngine.Debug.Log(""Dispose event invoked!"")")]
    [ShowInInspector, InfoBox("When you change the type of this field, or set it to null, the former property setup is disposed. The property setup will also be disposed when you deselect this example."), DisplayAsString]
    public BaseClass PolymorphicField;

    public abstract class BaseClass { public override string ToString() { return this.GetType().Name; } }
    public class A : BaseClass { }
    public class B : BaseClass { }
    public class C : BaseClass { }
}

Constructors

OnInspectorDisposeAttribute(String)
public OnInspectorDisposeAttribute(string action)
Parameters
System.String action

Fields

Action
public string Action