Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Node

The base class for all user-accessible nodes in a graph.
Read time 3 minutesLast updated 6 days ago

Definition

public abstract class Node : INode

Remarks

Inherit from this class to define custom node types that appear in the graph. The Node class provides lifecycle hooks, serialization support, and the structure needed to define ports, UI behaviors, and custom logic. This class forms the foundation of all user-defined nodes in a graph-based tool, including variable nodes, context nodes, and subgraph nodes.
To create a custom node, derive from Node, define its input and output ports using a port builder in Node.OnDefinePorts, and define its INodeOptions in Node.OnDefineOptions.
To customize the VisualElement generated for a node, derive from NodeView<T> with your node type as the type argument, and add custom UI in the lifecycle callbacks it exposes.
This class is used in combination with other types like INode, IPort, and Node.Graph to construct and manage node-based workflows.

Properties

Property

Description

DefaultColorThe highlight color of the node. The highlight is located on the upper border of nodes, and on the upper and lower borders of context nodes.
FillAmountThe progress fill amount displayed on the node's accent bar, expressed as a percentage.
GraphThe Node.Graph that contains this node.
IDThe globally unique identifier for this node.
InputPortCountThe number of input ports on the node.
NodeOptionCountThe number of node options defined in the node.
NodeOptionsThe node options defined on this node.
OutputPortCountThe number of output ports on the node.
PositionThe position of the node in the graph.
SubtitleThe secondary text displayed in the node's header.
TitleThe main text displayed in the node's header.
TooltipThe text displayed when hovering over the node's header.

Methods

Method

Description

DefineNodeDefines the structure of the node by building its ports and options.
GetInputPortRetrieves an input port using its index.
GetInputPortByNameRetrieves an input port using its name.
GetInputPortsRetrieves all input ports on the node in the order they are displayed.
GetNodeOptionRetrieves a node option using its zero-based index.
GetNodeOptionByNameRetrieves a node option using its name.
GetOutputPortRetrieves an output port using its index in the displayed order.
GetOutputPortByNameRetrieves an output port using its name.
GetOutputPortsRetrieves all output ports on the node in the order they are displayed.
OnDefineOptionsCalled during Node.DefineNode to define the options available on the node.
OnDefinePortsCalled during Node.DefineNode to define the input and output ports of the node.
OnDisableCalled when the node is removed or when the graph is disabled.
OnEnableCalled when the node is created or when the graph is enabled.
OnPortDataTypeChangedCalled when the data type of one of this node's ports changes.
RemoveFromGraphRemoves the node from its graph.

Interfaces

Interface

Description

Node.IOptionDefinitionContextInterface that provides methods to declare node options inside a node.
Node.IPortDefinitionContextInterface that provides methods to define input and output ports during Node.OnDefinePorts execution.