InspectorPropertyExtensions
Extension methods for Odin Inspector's InspectorProperty. Provides convenience helpers for drawing children, managing persistent state, navigating the property tree (parent/child lookup by name or type), accessing drawers, and computing indentation.
Definition
Namespace: Paragon.Editor
Assembly: Editor assembly
public static class InspectorPropertyExtensionsDependencies: Sirenix.OdinInspector.Editor, Sirenix.OdinInspector.Editor.Drawers, Sirenix.Utilities
Quick Lookup
Draw all child properties
property.DrawChildren()
Get persistent state
property.GetState<bool>("key", false)
Set persistent state
property.SetState("key", value)
Get typed property value
property.GetPropertyValue<MyType>()
Find parent by name
property.FindParentWithName("name")
Find parent by value type
property.FindParentOfType<MyComponent>()
Get parent's typed value
property.FindParentValueOfType<MyComponent>()
Find child by name
property.FindChildWithName("name")
Find child by value type
property.FindChildOfType<MyData>()
Get child's typed value
property.FindChildValueOfType<MyData>()
Get a specific drawer
property.GetDrawer<MyDrawer>()
Get current indentation
property.GetCurrentDrawerIndentation()
Methods
DrawChildren
Iterates and draws all children of the specified property.
inspectorProperty
InspectorProperty
The property whose children to draw
GetState<T>
Retrieves a named state value from the property's persistent state. Creates the state with the default value if it doesn't exist.
inspectorProperty
InspectorProperty
The property to retrieve state from
name
string
State key name
defaultValue
T
Default value if state doesn't exist
Returns: The state value of type T.
State is created with persistent = true (second parameter to state.Create), meaning it survives Inspector redraws and domain reloads within the same session.
SetState<T>
Sets a named state value in the property's persistent state. Creates the state if it doesn't exist.
inspectorProperty
InspectorProperty
The property to set state in
name
string
State key name
value
T
Value to set
GetPropertyValue<TValue>
Gets the property's value cast to the specified type. Accesses ValueEntry.WeakSmartValue and performs a direct cast.
Returns: The property value as TValue.
Throws InvalidCastException if the property's value is not of type TValue. No null checking is performed.
FindParentWithName
Finds a parent property matching the specified name.
inspectorProperty
InspectorProperty
—
Starting property
name
string
—
Name to match
includeSelf
bool
false
Include the starting property in the search
Returns: The matching parent, or null if not found.
FindParentOfType<T>
Finds a parent property whose value is of the specified type. Uses is T pattern matching on WeakSmartValue.
Returns: The matching parent, or null if not found.
FindParentValueOfType<TValue>
Combines FindParentOfType<TValue> and GetPropertyValue<TValue> — finds a parent by value type and returns its typed value.
Returns: The typed value of the matching parent.
Throws NullReferenceException if no parent of the specified type is found, because GetPropertyValue is called on the null result from FindParentOfType.
FindChildWithName
Finds a child property matching the specified name.
Returns: The matching child, or null if not found.
FindChildOfType<T>
Finds a child property whose value is of the specified type.
Returns: The matching child, or null if not found.
FindChildValueOfType<TValue>
Combines FindChildOfType<TValue> and GetPropertyValue<TValue> — finds a child by value type and returns its typed value.
Returns: The typed value of the matching child.
Throws NullReferenceException if no child of the specified type is found.
GetDrawer (Type)
Retrieves a specific drawer from the property's active drawer chain by type.
inspectorProperty
InspectorProperty
The property to search
drawerType
Type
The drawer type to find
Returns: The matching OdinDrawer, or null if not found. Uses IsOfType() for matching, which handles generic type inheritance.
GetDrawer<TDrawer>
Generic version — retrieves a drawer of the specified type from the active drawer chain.
Returns: The matching drawer as TDrawer, or null if not found. Uses is TDrawer pattern matching.
GetCurrentDrawerIndentation
Computes the indentation level for the current active drawer. Uses a priority-based resolution:
If the drawer has a
[DrawerIndentation]attribute → use itsIndentationvalueIf the drawer is
CollectionDrawer<>→ return3(base indent5 - 2)If the drawer is
NullableReferenceDrawer<>→ return4(if value is null) or3(if value exists)If the drawer is
CompositeDrawer→ return4(if no children) or3(if has children)Otherwise → return
5(default)
Returns: An int indentation level (typically 3–5).
The base indentation constant is 5. The DrawerIndentationAttribute is a custom Paragon attribute that allows drawers to specify their own indentation level, overriding the built-in heuristics.
Common Pitfalls
FindParentValueOfType / FindChildValueOfType can throw
These convenience methods chain Find*OfType → GetPropertyValue, which throws NullReferenceException if no matching property is found. Always ensure the target type exists in the hierarchy, or use FindParentOfType / FindChildOfType with a null check instead.
GetPropertyValue uses direct cast
GetPropertyValue<T>() performs (T)WeakSmartValue — no as cast or null safety. Ensure the type parameter matches the actual value type, or catch InvalidCastException.
GetState creates persistent state
State created via GetState is persistent (true flag). This means the state value persists across Inspector redraws. If you need transient state, use Odin's PropertyState API directly with persistent: false.
Examples
Custom drawer with state management
Finding parent component in nested drawer
See Also
PropertyTreeExtensions — PropertyTree extension methods
Sirenix Extensions README — Overview of Odin Inspector extensions
Editor Extensions README — Overview of all editor extensions
Last updated