# OnDefinePorts(IPortDefinitionContext)

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

## Definition

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

```csharp
protected virtual void OnDefinePorts(Node.IPortDefinitionContext context)
```

### Parameters

**** (\[IPortDefinitionContext]\(/engine/6000.6/script-reference/unity/graphtoolkit/editor/node/iportdefinitioncontext)): Provides methods for defining input and output ports.

### Remarks

This method is called after [Node.OnDefineOptions](/engine/6000.6/script-reference/unity/graphtoolkit/editor/node/ondefineoptions.md) and is used to declare the structure of the node's connectivity. Use the provided [Node.IPortDefinitionContext](/engine/6000.6/script-reference/unity/graphtoolkit/editor/node/iportdefinitioncontext.md) 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](/engine/6000.6/script-reference/unity/graphtoolkit/editor/node/getinputportbyname.md).

### Examples

```csharp
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();
}
```
