docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IPort

    Interface for a node port.

    Namespace: Unity.GraphToolkit.Editor
    Assembly: Unity.GraphToolkit.Common.Editor.dll
    Syntax
    public interface IPort
    Remarks

    Use this interface to access port metadata and connectivity.

    A port represents an input or output slot on a node and users can connect ports to other ports to form graph relationships. Each port has a unique name within its node context, a data type, and a direction. Users can only connect a port to another port if they are compatible as follows:

    • The ports must have opposite PortDirection (i.e., one input and one output).
    • Either both ports must have the same data type or the output port must be a derived data type and the input port, a base data type. Of course the derived data type must be derived from the same base type.
    To retrieve the node that owns the port, use INodeExtensions.GetNode.

    Properties

    dataType

    Gets the data type associated with the port.

    Declaration
    Type dataType { get; }
    Property Value
    Type Description
    Type

    direction

    Gets the direction of the port.

    Declaration
    PortDirection direction { get; }
    Property Value
    Type Description
    PortDirection
    Remarks

    The direction indicates whether the port is an input or output. Use Input or Output to determine behavior.

    displayName

    Gets the label displayed in the UI for the port.

    Declaration
    string displayName { get; }
    Property Value
    Type Description
    string

    firstConnectedPort

    Gets the first port connected to this port, if any.

    Declaration
    IPort firstConnectedPort { get; }
    Property Value
    Type Description
    IPort
    Remarks

    If multiple connections exist, only the first connected port is returned.

    isConnected

    Indicates whether the port is currently connected to any other port.

    Declaration
    bool isConnected { get; }
    Property Value
    Type Description
    bool
    Remarks

    Use this property to check when a port has at least one connection.

    name

    Gets the unique identifier name of the port.

    Declaration
    string name { get; }
    Property Value
    Type Description
    string
    Remarks

    The name is used to retrieve the port programmatically using methods like Node.GetInputPortByName(string) or Node.GetOutputPortByName(string). It must be unique within its category (input or output) for a node.

    Methods

    GetConnectedPorts(List<IPort>)

    Retrieves all ports connected to this port.

    Declaration
    void GetConnectedPorts(List<IPort> outConnectedPorts)
    Parameters
    Type Name Description
    List<IPort> outConnectedPorts

    A list to populate with the connected ports.

    Remarks

    This method adds all connected ports to the provided list. It clears the list before adding items.

    TryGetValue<T>(out T)

    Tries to retrieve the current value assigned to the port’s UI field.

    Declaration
    bool TryGetValue<T>(out T value)
    Parameters
    Type Name Description
    T value

    When successful, contains the value assigned to the port’s field.

    Returns
    Type Description
    bool

    true if the port is not connected and a field value is available; otherwise, false.

    Type Parameters
    Name Description
    T

    The expected type of the value.

    Remarks

    This method is intended for editor-time inspection of an input port’s value, configured through a field displayed in the UI. If the port is connected, the field is hidden and no value is available, so the method returns false. If the value was never explicitly set, this method still returns true, and value will contain the default value for type T.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)