docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class CanvasNode

    A node-graph box, for Animator-style state machines and blend trees drawn inside a Canvas.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    CanvasNode
    Implements
    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder
    ISelectableElement
    Inherited Members
    BaseVisualElement.contextPrefix
    BaseVisualElement.densityOverride
    BaseVisualElement.themeOverride
    BaseVisualElement.langOverride
    BaseVisualElement.layoutDirectionOverride
    BaseVisualElement.preferredTooltipPlacementOverride
    BaseVisualElement.tooltipDelayMsOverride
    BaseVisualElement.GetLayoutDirectionUssClassName(Dir)
    VisualElement.disabledUssClassName
    VisualElement.SetActivePseudoState(bool)
    VisualElement.SetCheckedPseudoState(bool)
    VisualElement.Focus()
    VisualElement.SendEvent(EventBase)
    VisualElement.SetEnabledFromHierarchy(bool)
    VisualElement.SetEnabled(bool)
    VisualElement.MarkDirtyRepaint()
    VisualElement.IsMarkedForRepaint()
    VisualElement.ContainsPoint(Vector2)
    VisualElement.Overlaps(Rect)
    VisualElement.DoMeasure(float, VisualElement.MeasureMode, float, VisualElement.MeasureMode)
    VisualElement.ToString()
    VisualElement.GetClasses()
    VisualElement.ClearClassList()
    VisualElement.AddToClassList(string)
    VisualElement.RemoveFromClassList(string)
    VisualElement.ToggleInClassList(string)
    VisualElement.EnableInClassList(string, bool)
    VisualElement.ClassListContains(string)
    VisualElement.FindAncestorUserData()
    VisualElement.SetBinding(BindingId, Binding)
    VisualElement.GetBinding(BindingId)
    VisualElement.TryGetBinding(BindingId, out Binding)
    VisualElement.GetBindingInfos()
    VisualElement.GetBindingInfos(List<BindingInfo>)
    VisualElement.HasBinding(BindingId)
    VisualElement.ClearBinding(BindingId)
    VisualElement.ClearBindings()
    VisualElement.GetHierarchicalDataSourceContext()
    VisualElement.GetDataSourceContext(BindingId)
    VisualElement.TryGetDataSourceContext(BindingId, out DataSourceContext)
    VisualElement.TryGetLastBindingToUIResult(in BindingId, out BindingResult)
    VisualElement.TryGetLastBindingToSourceResult(in BindingId, out BindingResult)
    VisualElement.Add(VisualElement)
    VisualElement.Insert(int, VisualElement)
    VisualElement.Remove(VisualElement)
    VisualElement.RemoveAt(int)
    VisualElement.Clear()
    VisualElement.ElementAt(int)
    VisualElement.IndexOf(VisualElement)
    VisualElement.Children()
    VisualElement.Sort(Comparison<VisualElement>)
    VisualElement.BringToFront()
    VisualElement.SendToBack()
    VisualElement.PlaceBehind(VisualElement)
    VisualElement.PlaceInFront(VisualElement)
    VisualElement.RemoveFromHierarchy()
    VisualElement.GetFirstOfType<T>()
    VisualElement.GetFirstAncestorOfType<T>()
    VisualElement.Contains(VisualElement)
    VisualElement.FindCommonAncestor(VisualElement)
    VisualElement.viewDataKey
    VisualElement.userData
    VisualElement.canGrabFocus
    VisualElement.focusController
    VisualElement.disablePlayModeTint
    VisualElement.usageHints
    VisualElement.transform
    VisualElement.scaledPixelsPerPoint
    VisualElement.layout
    VisualElement.contentRect
    VisualElement.paddingRect
    VisualElement.worldBound
    VisualElement.localBound
    VisualElement.worldTransform
    VisualElement.hasActivePseudoState
    VisualElement.hasInactivePseudoState
    VisualElement.hasHoverPseudoState
    VisualElement.hasCheckedPseudoState
    VisualElement.hasEnabledPseudoState
    VisualElement.hasDisabledPseudoState
    VisualElement.hasFocusPseudoState
    VisualElement.hasRootPseudoState
    VisualElement.pickingMode
    VisualElement.name
    VisualElement.enabledInHierarchy
    VisualElement.enabledSelf
    VisualElement.languageDirection
    VisualElement.visible
    VisualElement.generateVisualContent
    VisualElement.dataSource
    VisualElement.dataSourcePath
    VisualElement.dataSourceType
    VisualElement.experimental
    VisualElement.hierarchy
    VisualElement.cacheAsBitmap
    VisualElement.parent
    VisualElement.panel
    VisualElement.visualTreeAssetSource
    VisualElement.this[int]
    VisualElement.childCount
    VisualElement.schedule
    VisualElement.style
    VisualElement.resolvedStyle
    VisualElement.customStyle
    VisualElement.styleSheets
    VisualElement.tooltip
    Focusable.Blur()
    Focusable.focusable
    Focusable.tabIndex
    Focusable.delegatesFocus
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, CallbackOptions)
    CallbackEventHandler.UnregisterAllRemovableCallbacks()
    CallbackEventHandler.HasTrickleDownHandlers()
    CallbackEventHandler.HasBubbleUpHandlers()
    CallbackEventHandler.ExecuteDefaultActionAtTarget(EventBase)
    CallbackEventHandler.HandleEventBubbleUp(EventBase)
    CallbackEventHandler.HandleEventTrickleDown(EventBase)
    CallbackEventHandler.ExecuteDefaultAction(EventBase)
    CallbackEventHandler.NotifyPropertyChanged(in BindingId)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.AppUI.UI
    Assembly: Unity.AppUI.dll
    Syntax
    [UxmlElement]
    public class CanvasNode : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, ISelectableElement
    Remarks

    A titled header, an optional body and labelled input/output ports down the left and right edges. Place it with x and y in the canvas' content space, set movable for drag-to-move, and connect two ports with a CanvasEdge.

    The node lives inside a Canvas and owns none of its pan or zoom: the canvas applies its zoom as a transform on the viewport container, so a drag delta converted through the node's parent is already in content space. That is why this component has no zoom property of its own, unlike the web original, which has to divide its pointer deltas by the zoom by hand.

    headerHeight, portRowHeight and portsPaddingY are the published geometry an edge routes against, and GetPortAnchor(CanvasPortSide, int) turns them into a content-space point. They are compile-time constants, so the stylesheet expresses the same geometry through the static sizing ramp — the one ramp that does not rescale with density — and the two cannot drift apart.

    Examples

    Two connected nodes.

    var from = new CanvasNode
    {
        title = "Idle",
        x = 0, y = 0,
        outputPorts = new[] { new CanvasPort("out", "Next") },
    };
    var to = new CanvasNode
    {
        title = "Run",
        x = 260, y = 80,
        inputPorts = new[] { new CanvasPort("in", "Previous") },
    };
    var edge = new CanvasEdge
    {
        from = from.GetPortAnchor(CanvasPortSide.Output, 0),
        to = to.GetPortAnchor(CanvasPortSide.Input, 0),
        isDirectional = true,
    };
    canvas.Add(edge);  // edges first, so nodes paint on top
    canvas.Add(from);
    canvas.Add(to);

    In UXML.

    <appui:CanvasNode title="Idle" variant="Entry" movable="true" />

    Constructors

    CanvasNode()

    Default constructor.

    Declaration
    public CanvasNode()

    Fields

    bodyUssClassName

    The styling class of the body, which holds the node's children.

    Declaration
    public const string bodyUssClassName = "appui-canvas-node__body"
    Field Value
    Type Description
    string

    defaultWidth

    The node's default width, in pixels.

    Declaration
    public const float defaultWidth = 180
    Field Value
    Type Description
    float
    Remarks

    Density-invariant: the stylesheet draws it from --appui-static-sizing-2250.

    grabbingUssClassName

    The styling class of a node currently being dragged.

    Declaration
    public const string grabbingUssClassName = "appui-canvas-node--grabbing"
    Field Value
    Type Description
    string

    headerHeight

    The height of the node's header, in pixels.

    Declaration
    public const float headerHeight = 30
    Field Value
    Type Description
    float
    Remarks

    Density-invariant: the stylesheet draws it from --appui-static-sizing-375.

    headerUssClassName

    The styling class of the header.

    Declaration
    public const string headerUssClassName = "appui-canvas-node__header"
    Field Value
    Type Description
    string

    lodUssClassName

    The CanvasNode level-of-detail styling class.

    Declaration
    public const string lodUssClassName = "appui-canvas-node--lod-"
    Field Value
    Type Description
    string

    movableUssClassName

    The styling class of a node that can be dragged.

    Declaration
    public const string movableUssClassName = "appui-canvas-node--movable"
    Field Value
    Type Description
    string

    portColumnUssClassName

    The styling class of a column of ports.

    Declaration
    public const string portColumnUssClassName = "appui-canvas-node__ports--"
    Field Value
    Type Description
    string

    portDotUssClassName

    The styling class of a port's dot.

    Declaration
    public const string portDotUssClassName = "appui-canvas-node__port-dot"
    Field Value
    Type Description
    string

    portHitUssClassName

    The styling class of a port's pointer target.

    Declaration
    public const string portHitUssClassName = "appui-canvas-node__port-hit"
    Field Value
    Type Description
    string

    portLabelUssClassName

    The styling class of a port's label.

    Declaration
    public const string portLabelUssClassName = "appui-canvas-node__port-label"
    Field Value
    Type Description
    string

    portRowHeight

    The height of one port row, in pixels.

    Declaration
    public const float portRowHeight = 24
    Field Value
    Type Description
    float
    Remarks

    Density-invariant: the stylesheet draws it from --appui-static-sizing-300.

    portRowUssClassName

    The styling class of one port row.

    Declaration
    public const string portRowUssClassName = "appui-canvas-node__port-row"
    Field Value
    Type Description
    string

    portsPaddingY

    The vertical padding above the first port row and below the last, in pixels.

    Declaration
    public const float portsPaddingY = 8
    Field Value
    Type Description
    float
    Remarks

    Density-invariant: the stylesheet draws it from --appui-static-sizing-100.

    portsUssClassName

    The styling class of the port area.

    Declaration
    public const string portsUssClassName = "appui-canvas-node__ports"
    Field Value
    Type Description
    string

    positionedUssClassName

    The styling class of a node placed at an explicit position.

    Declaration
    public const string positionedUssClassName = "appui-canvas-node--positioned"
    Field Value
    Type Description
    string

    titleUssClassName

    The styling class of the header's title.

    Declaration
    public const string titleUssClassName = "appui-canvas-node__title"
    Field Value
    Type Description
    string

    ussClassName

    The CanvasNode main styling class.

    Declaration
    public const string ussClassName = "appui-canvas-node"
    Field Value
    Type Description
    string

    variantUssClassName

    The CanvasNode variant styling class.

    Declaration
    public const string variantUssClassName = "appui-canvas-node--"
    Field Value
    Type Description
    string

    Properties

    contentContainer

    The node's body, which is also its content container.

    Declaration
    public override VisualElement contentContainer { get; }
    Property Value
    Type Description
    VisualElement
    Overrides
    VisualElement.contentContainer

    header

    The header element, exposed so a caller can style or decorate it.

    Declaration
    public VisualElement header { get; }
    Property Value
    Type Description
    VisualElement

    inputPorts

    The ports down the node's left edge.

    Declaration
    public IEnumerable<CanvasPort> inputPorts { get; set; }
    Property Value
    Type Description
    IEnumerable<CanvasPort>
    Remarks

    Setting this rebuilds the input column. Null or empty removes every input row.

    lod

    How much of the node to draw. Full by default.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public CanvasLevelOfDetail lod { get; set; }
    Property Value
    Type Description
    CanvasLevelOfDetail
    Remarks

    Compact hides the port labels and the body. Box also hides the title and the port dots, leaving the header colour over the port area. Every level keeps the header and port rows' geometry, so edges anchored with GetPortAnchor(CanvasPortSide, int) still meet the node. Pick the level from the canvas zoom with LevelOfDetailForZoom(float, float, float).

    movable

    Whether the node can be dragged with the primary pointer. False by default.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public bool movable { get; set; }
    Property Value
    Type Description
    bool
    Remarks

    A movable node moves itself and reports the result through positionChanged. It also stops the press from reaching the canvas, so dragging a node never pans the canvas.

    outputPorts

    The ports down the node's right edge.

    Declaration
    public IEnumerable<CanvasPort> outputPorts { get; set; }
    Property Value
    Type Description
    IEnumerable<CanvasPort>
    Remarks

    Setting this rebuilds the output column. Null or empty removes every output row.

    selected

    Whether the node is selected. False by default.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public bool selected { get; set; }
    Property Value
    Type Description
    bool

    title

    The header label. Null or empty hides the header entirely.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public string title { get; set; }
    Property Value
    Type Description
    string

    variant

    The node's colour role. Default by default.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public CanvasNodeVariant variant { get; set; }
    Property Value
    Type Description
    CanvasNodeVariant

    width

    The node's width in pixels. defaultWidth by default.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public float width { get; set; }
    Property Value
    Type Description
    float

    x

    The node's X coordinate in the canvas' content space. Unset leaves the node in normal flow.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public Optional<float> x { get; set; }
    Property Value
    Type Description
    Optional<float>

    y

    The node's Y coordinate in the canvas' content space. Unset leaves the node in normal flow.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public Optional<float> y { get; set; }
    Property Value
    Type Description
    Optional<float>

    Methods

    GetLodUssClassName(CanvasLevelOfDetail)

    Declaration
    public static string GetLodUssClassName(CanvasLevelOfDetail enumValue)
    Parameters
    Type Name Description
    CanvasLevelOfDetail enumValue
    Returns
    Type Description
    string

    GetPortAnchor(CanvasPortSide, int)

    The point an edge should attach to for one port, in the canvas' content space.

    Declaration
    public Vector2 GetPortAnchor(CanvasPortSide side, int index)
    Parameters
    Type Name Description
    CanvasPortSide side

    The side the port sits on.

    int index

    The port's index within that side.

    Returns
    Type Description
    Vector2

    The anchor point.

    Remarks

    Computed from headerHeight, portsPaddingY and portRowHeight, so it is usable while a graph is still being built, before the node has ever been laid out. It assumes the node is positioned: an unset x or y counts as zero, and a hidden header contributes no offset.

    The node's border is part of its box, so the ports are inset by one border width from the coordinates x and y name. That inset is added here once the border has resolved, which is what keeps an edge landing on the dot rather than a pixel beside it. Before the first layout the border resolves to zero and this returns exactly the registry's formula.

    GetPortColumnUssClassName(CanvasPortSide)

    Declaration
    public static string GetPortColumnUssClassName(CanvasPortSide enumValue)
    Parameters
    Type Name Description
    CanvasPortSide enumValue
    Returns
    Type Description
    string

    GetPortCount(CanvasPortSide)

    The number of ports on one side.

    Declaration
    public int GetPortCount(CanvasPortSide side)
    Parameters
    Type Name Description
    CanvasPortSide side

    The side to count.

    Returns
    Type Description
    int

    The number of ports on that side.

    GetPortElement(CanvasPortSide, int)

    The row element that draws one port, or null when the index is out of range.

    Declaration
    public VisualElement GetPortElement(CanvasPortSide side, int index)
    Parameters
    Type Name Description
    CanvasPortSide side

    The side the port sits on.

    int index

    The port's index within that side.

    Returns
    Type Description
    VisualElement

    The row element, or null.

    GetVariantUssClassName(CanvasNodeVariant)

    Declaration
    public static string GetVariantUssClassName(CanvasNodeVariant enumValue)
    Parameters
    Type Name Description
    CanvasNodeVariant enumValue
    Returns
    Type Description
    string

    SetSelectedWithoutNotify(bool)

    Sets the selected state without notifying.

    Declaration
    public void SetSelectedWithoutNotify(bool newValue)
    Parameters
    Type Name Description
    bool newValue

    The new selected state.

    Events

    portPointerDown

    Raised when a pointer goes down on a port — begin dragging a new connection from it.

    Declaration
    public event Action<CanvasPortEvent> portPointerDown
    Event Type
    Type Description
    Action<CanvasPortEvent>

    portPointerEntered

    Raised when a pointer enters a port, which is where a dragged connection would snap to it.

    Declaration
    public event Action<CanvasPortEvent> portPointerEntered
    Event Type
    Type Description
    Action<CanvasPortEvent>

    portPointerLeft

    Raised when a pointer leaves a port.

    Declaration
    public event Action<CanvasPortEvent> portPointerLeft
    Event Type
    Type Description
    Action<CanvasPortEvent>

    portPointerUp

    Raised when a pointer is released on a port — drop a connection onto it. Validate in the handler.

    Declaration
    public event Action<CanvasPortEvent> portPointerUp
    Event Type
    Type Description
    Action<CanvasPortEvent>

    positionChanged

    Raised while a movable node is dragged, with its next content-space position.

    Declaration
    public event Action<Vector2> positionChanged
    Event Type
    Type Description
    Action<Vector2>
    Remarks

    The node has already moved itself by the time this fires; the event exists so the caller can persist the position and re-route any edges attached to it.

    selectRequested

    Raised when the node is pressed with the primary button, so the caller can select it.

    Declaration
    public event Action selectRequested
    Event Type
    Type Description
    Action
    Remarks

    A pan press inside a Canvas -- the middle button, or the primary button with the pan modifier held -- is taken by the canvas before the node sees it, so it never selects.

    Implements

    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder
    ISelectableElement

    Extension Methods

    VisualElementExtensions.FindNavController(VisualElement)
    RegisterUpdateCallbackExtensions.RegisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    RegisterUpdateCallbackExtensions.UnregisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    VisualElementExtensions.EnableDynamicTransform(VisualElement, bool)
    VisualElementExtensions.EnablePicking(VisualElement, bool)
    VisualElementExtensions.GetChildren<T>(VisualElement, bool)
    VisualElementExtensions.GetContextProvider<T>(VisualElement)
    VisualElementExtensions.GetContextProvider<T>(VisualElement, string)
    VisualElementExtensions.GetContext<T>(VisualElement)
    VisualElementExtensions.GetContext<T>(VisualElement, string)
    VisualElementExtensions.GetExclusiveRootElement(VisualElement)
    VisualElementExtensions.GetLastAncestorOfType<T>(VisualElement)
    VisualElementExtensions.GetPreferredTooltipPlacement(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement, string)
    VisualElementExtensions.GetTooltipContent(VisualElement)
    VisualElementExtensions.GetTooltipTemplate(VisualElement)
    VisualElementExtensions.HasAncestorOfType<T>(VisualElement, bool)
    VisualElementExtensions.HasAncestorsOfType<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement, string)
    VisualElementExtensions.IsInvisible(VisualElement)
    VisualElementExtensions.IsOnScreen(VisualElement)
    VisualElementExtensions.ProvideContext<T>(VisualElement, string, T)
    VisualElementExtensions.ProvideContext<T>(VisualElement, T)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.SetPreferredTooltipPlacement(VisualElement, OptionalEnum<PopoverPlacement>)
    VisualElementExtensions.SetTooltipContent(VisualElement, VisualElementExtensions.TooltipContentCallback)
    VisualElementExtensions.SetTooltipTemplate(VisualElement, VisualElement)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    In This Article
    Back to top
    Copyright © 2026 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)