Odin has a dedicated attribute overview with examples

OnValueChangedAttribute 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 = true)]
public sealed class OnValueChangedAttribute : Attribute, _Attribute

OnValueChanged works on properties and fields, and calls the specified function whenever the value has been changed via the inspector.

  • System.Object
  • System.Attribute
  • OnValueChangedAttribute


Note that this attribute only works in the editor! Properties changed by script will not call the function.


The following example shows how OnValueChanged is used to provide a callback for a property.

public class MyComponent : MonoBehaviour
	public int MyInt;

	private void MyCallback()
		// ..

The following example show how OnValueChanged can be used to get a component from a prefab property.

public class MyComponent : MonoBehaviour
	public GameObject MyPrefab;

	// RigidBody component of MyPrefab.
	[SerializeField, HideInInspector]
	private RigidBody myPrefabRigidbody;

	private void OnPrefabChange()
		if(MyPrefab != null)
			myPrefabRigidbody = MyPrefab.GetComponent<Rigidbody>();
			myPrefabRigidbody = null;


OnValueChangedAttribute(String, Boolean)
Adds a callback for when the property's value is changed.
public OnValueChangedAttribute(string methodName, bool includeChildren = false)
System.String methodName

Name of the method.

System.Boolean includeChildren

Whether to invoke the method when a child value of the property is changed.


Whether to invoke the method when a child value of the property is changed.
public bool IncludeChildren
Name of callback member function.
public string MethodName

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.