# OnCullingChanged(bool)

> Called when the state's culling state changes.

## Definition

* **Type:** Method
* **Namespace:** [Unity.GraphToolkit.Editor](/engine/6000.7/script-reference/unity/graphtoolkit/editor.md)
* **Assembly:** UnityEditor

```csharp
public virtual void OnCullingChanged(bool cullingEnabled)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): `true` when the state has just been culled; `false` when the state has just returned from being culled.

### Remarks

States are culled when they are off-screen or too small to render at the current zoom level. When the state returns from being culled (`cullingEnabled` is `false`), the contents of [IStateView.Root](/engine/6000.7/script-reference/unity/graphtoolkit/editor/istateview/root.md) have been cleared and the built-in parts have been rebuilt. Re-add any custom UI you allocated in [StateView\<T>.OnViewBuilt](/engine/6000.7/script-reference/unity/graphtoolkit/editor/stateview1/onviewbuilt.md).

Cache references to your custom elements in fields so this callback can re-parent them via `View.Root.Add(...)` without allocating new ones.

When the state is being culled (`cullingEnabled` is `true`), you typically don't need to do anything; use this branch only if you need to release resources for culled states.

### Examples

```csharp
Label m_Label; // Allocated in OnViewBuilt.

public override void OnCullingChanged(bool cullingEnabled)
{
    if (!cullingEnabled && m_Label != null)
    {
        // Root was cleared while culled — re-parent the cached label.
        View.Root.Add(m_Label);
    }
}
```
