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 InspectorPropertyExtensions

Dependencies: Sirenix.OdinInspector.Editor, Sirenix.OdinInspector.Editor.Drawers, Sirenix.Utilities

Quick Lookup

Goal
Method

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.

Parameter
Type
Description

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.

Parameter
Type
Description

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.

circle-info

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.

Parameter
Type
Description

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.

circle-exclamation

FindParentWithName

Finds a parent property matching the specified name.

Parameter
Type
Default
Description

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.

circle-exclamation

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.

circle-exclamation

GetDrawer (Type)

Retrieves a specific drawer from the property's active drawer chain by type.

Parameter
Type
Description

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:

  1. If the drawer has a [DrawerIndentation] attribute → use its Indentation value

  2. If the drawer is CollectionDrawer<> → return 3 (base indent 5 - 2)

  3. If the drawer is NullableReferenceDrawer<> → return 4 (if value is null) or 3 (if value exists)

  4. If the drawer is CompositeDrawer → return 4 (if no children) or 3 (if has children)

  5. Otherwise → return 5 (default)

Returns: An int indentation level (typically 3–5).

circle-info

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

circle-exclamation
circle-exclamation
circle-exclamation

Examples

Custom drawer with state management

Finding parent component in nested drawer

See Also

Last updated