# NodeView<T>

> Derive from this class to add custom UI to the view generated for a specific NodeView<T>.Node type.

## Definition

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

```csharp
public class NodeView<T> where T : Node
```

## Remarks

A [VisualElement](/engine/6000.7/script-reference/unityengine/uielements/visualelement.md) is built for every [NodeView\<T>.Node](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/node.md) that appears in a graph. A [NodeView\<T>](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1.md) lets you inject custom UI into that generated element. Subclasses are discovered by their type parameter: for a [NodeView\<T>.Node](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/node.md) of type `T`, the concrete [NodeView\<T>](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1.md) whose type argument matches is used, walking up the [NodeView\<T>.Node](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/node.md) inheritance chain if there is no exact match.

The [NodeView\<T>.Node](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/node.md) instance is available through [NodeView\<T>.Node](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/node.md) once the view is constructed. Access the generated visual element through [NodeView\<T>.View](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/view.md) and add custom UI to [INodeView.Root](/engine/6000.7/script-reference/unity/graphtoolkit/editor/inodeview/root.md).

Allocate custom UI in [NodeView\<T>.OnViewBuilt](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/onviewbuilt.md) and re-add it in [NodeView\<T>.OnCullingChanged](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/oncullingchanged.md) (when `cullingEnabled` is `false`). Do not allocate UI in [NodeView\<T>.OnViewAttached](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/onviewattached.md): that callback can fire multiple times during a node's lifetime — for example when the user tabs away from and back to the graph view, or when a block node is dragged and re-parented — and any UI you allocate there accumulates as duplicates. When a node returns from being culled, the contents of [INodeView.Root](/engine/6000.7/script-reference/unity/graphtoolkit/editor/inodeview/root.md) are cleared, so a cached reference is no longer parented; re-add it from [NodeView\<T>.OnCullingChanged](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/oncullingchanged.md) to avoid allocating a new element.

Additional Resources: [NodeView\<T>.Node](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/node.md), [INodeView](/engine/6000.7/script-reference/unity/graphtoolkit/editor/inodeview.md)

## Examples

```csharp
// The Node type that this view customizes.
class MyNode : Node
{
    protected override void OnDefinePorts(IPortDefinitionContext context)
    {
        context.AddInputPort<float>("input");
    }
}

// This view is constructed for every MyNode instance in a graph.
class MyNodeView : NodeView<MyNode>
{
    Label m_Label;

    public override void OnViewBuilt()
    {
        // Allocate custom UI once, after the built-in UI is ready and before the node attaches to a
        // panel. Cache the reference so OnCullingChanged can re-add it without allocating again.
        m_Label = new Label($"Node: {Node.Title}");
        View.Root.Add(m_Label);
    }

    public override void OnCullingChanged(bool cullingEnabled)
    {
        // When cullingEnabled is false, the node has just returned from being culled and Root has
        // been cleared. Re-add the cached element — no allocation needed.
        if (!cullingEnabled && m_Label != null)
            View.Root.Add(m_Label);
    }
}
```

## Properties

| Property                                                                            | Description                                                                                                                                       |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Node](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/node.md) | The [NodeView\<T>.Node](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/node.md) instance this view customizes.               |
| [View](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/view.md) | The generated view for this node. Add custom UI to [INodeView.Root](/engine/6000.7/script-reference/unity/graphtoolkit/editor/inodeview/root.md). |

## Methods

| Method                                                                                                      | Description                                                                                                                                                                                           |
| ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [OnCullingChanged](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/oncullingchanged.md) | Called when the node's culling state changes.                                                                                                                                                         |
| [OnViewAttached](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/onviewattached.md)     | Called when the node's [INodeView.Root](/engine/6000.7/script-reference/unity/graphtoolkit/editor/inodeview/root.md) is attached to a UI panel.                                                       |
| [OnViewBuilt](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/onviewbuilt.md)           | Called once, after the node's built-in UI is fully constructed and before its [VisualElement](/engine/6000.7/script-reference/unityengine/uielements/visualelement.md) is attached to the graph view. |
| [OnViewDetached](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/onviewdetached.md)     | Called when the node's [INodeView.Root](/engine/6000.7/script-reference/unity/graphtoolkit/editor/inodeview/root.md) is detached from its UI panel.                                                   |
| [OnViewLODChanged](/engine/6000.7/script-reference/unity/graphtoolkit/editor/nodeview1/onviewlodchanged.md) | Called when the graph view's zoom level changes.                                                                                                                                                      |
