Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


OnDefinePorts(IPortDefinitionContext)

Called during Node.DefineNode to define the input and output ports of the node.
Read time 1 minuteLast updated 11 days ago

Definition

protected virtual void OnDefinePorts(Node.IPortDefinitionContext context)

Parameters

Provides methods for defining input and output ports.

Remarks

This method is called after Node.OnDefineOptions and is used to declare the structure of the node's connectivity. Use the provided Node.IPortDefinitionContext to define input and output ports using a builder pattern. The port builder pattern enables fluent configuration of ports by chaining methods such as
WithDisplayName
,
WithDefaultValue
, or
WithConnectorUI
, followed by
Build()
to finalize the port. The
portName
parameter passed to
AddInputPort
or
AddOutputPort
serves as the port's unique identifier. The
portName
parameter must be unique within its direction (input or output) on the node and is also used as the display name unless you explicitly call
WithDisplayName
. You also use the
portName
identifier to call Node.GetInputPortByName.

Examples

protected override void OnDefinePorts(IPortDefinitionContext context){ var inputPort = context.AddInputPort<string>("stringInput") .WithDisplayName("String Input") .WithDefaultValue("Default Value") .Build(); var outputPort = context.AddOutputPort("myOutput") .WithDisplayName("My Output Port") .WithDataType(typeof(float)) .WithConnectorUI(PortConnectorUI.Arrowhead) .Build();}