docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IVariable

    Interface for a graph variable.

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

    Variables are data containers that are accessible throughout a graph. You can manage variables in the Blackboard and reference them with variable nodes. A variable has a name, a data type, a kind that defines its visibility within subgraphs, and an optional default value. Use TryGetDefaultValue<T>(out T) to retrieve the default value if one exists. Variables are distinct from variable nodes. However, you can drag variables onto the graph canvas, where they are instantiated as variable nodes.

    Properties

    dataType

    Gets the data type of the variable.

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

    This type determines the value type the variable holds and influences the data type of the ports created by corresponding variable nodes.

    name

    Gets the name of the variable.

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

    This name is used to identify the variable in the UI and when matching references in the graph.

    variableKind

    Gets the kind of the variable, such as Local, Input, or Output.

    Declaration
    VariableKind variableKind { get; }
    Property Value
    Type Description
    VariableKind
    Remarks

    This property defines the scope of the variable. Use Local for variables used only within the current graph. Use Input or Output to expose variables to or from a subgraph. This value does not determine the PortDirection of the port on the variable node.

    Methods

    TryGetDefaultValue<T>(out T)

    Tries to retrieve the default value of the variable.

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

    The retrieved default value, if available.

    Returns
    Type Description
    bool

    true if a default value exists and is of the correct type; otherwise, false.

    Type Parameters
    Name Description
    T

    The expected type of the default value.

    Remarks

    Use this method to retrieve the variable’s default value in a type-safe way.

    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)