Version: Unity 6.4 Alpha (6000.4)
LanguageEnglish
  • C#

Node.OnDefinePorts

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

protected void OnDefinePorts(Unity.GraphToolkit.Editor.Node.IPortDefinitionContext context);

Parameters

Parameter Description
context Provides methods for defining input and output ports.

Description

Called during DefineNode to define the input and output ports of the node.

This method is called after OnDefineOptions and is used to declare the structure of the node's connectivity. Use the provided 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.

 protected override void OnDefinePorts(IPortDefinitionContext context)
 {
     var inputPort = context.AddInputPort&lt;string&gt;("stringInput")
         .WithDisplayName("String Input")
         .WithDefaultValue("Default Value")
         .Build();

var outputPort = context.AddOutputPort("myOutput") .WithDisplayName("My Output Port") .WithDataType(typeof(float)) .WithConnectorUI(PortConnectorUI.Arrowhead) .Build(); }