docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class CanvasEdge

    A connection line between two points in a Canvas, drawn with Painter2D.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    CanvasEdge
    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.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.contentContainer
    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 CanvasEdge : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, ISelectableElement
    Remarks

    Pair it with CanvasNode: GetPortAnchor(CanvasPortSide, int) gives the two points, and the edge positions itself over the bounding box that covers them, so from and to are in the same content-space units as a node's x and y. Add edges before nodes, so nodes paint on top.

    Picking follows the line, not the box. The web draws a second, transparent, fat path to make a thin line clickable; here ContainsPoint(Vector2) answers with the distance from the pointer to the sampled path, so there is no second path to keep in sync with the first.

    Every colour the painter uses is read from a custom style property, because a colour written in C# is a colour the theme cannot reach. --edge-color and its siblings are declared in CanvasEdge.uss and bound to App UI tokens there.

    Examples

    An edge between two nodes' ports.

    var edge = new CanvasEdge
    {
        from = source.GetPortAnchor(CanvasPortSide.Output, 0),
        to = target.GetPortAnchor(CanvasPortSide.Input, 0),
        curveStyle = CanvasCurveStyle.Bezier,
        isDirectional = true,
    };
    canvas.Add(edge);

    In UXML.

    <appui:CanvasEdge curve-style="SmoothStep" is-directional="true" />

    Constructors

    CanvasEdge()

    Default constructor.

    Declaration
    public CanvasEdge()

    Fields

    activeUssClassName

    The styling class of an active edge.

    Declaration
    public const string activeUssClassName = "appui-canvas-edge--active"
    Field Value
    Type Description
    string

    curveStyleUssClassName

    The CanvasEdge curve style styling class.

    Declaration
    public const string curveStyleUssClassName = "appui-canvas-edge--"
    Field Value
    Type Description
    string

    defaultStrokeWidth

    The default stroke width, in pixels.

    Declaration
    public const float defaultStrokeWidth = 2
    Field Value
    Type Description
    float

    directionalUssClassName

    The styling class of a directional edge.

    Declaration
    public const string directionalUssClassName = "appui-canvas-edge--directional"
    Field Value
    Type Description
    string

    hitTolerance

    Half the width of the band around the line that answers a pick, in pixels.

    Declaration
    public const float hitTolerance = 7
    Field Value
    Type Description
    float
    Remarks

    A hairline is impossible to hit exactly, so the edge accepts a pointer within this distance of the path. It is the equivalent of the web's transparent fat hit-path.

    padding

    The margin left around the path's bounding box, in pixels, so a thick stroke and the arrowhead are not clipped by the element's own box.

    Declaration
    public const float padding = 16
    Field Value
    Type Description
    float

    ussClassName

    The CanvasEdge main styling class.

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

    Properties

    active

    Whether the edge is an active path, for instance the branch a blend tree is currently taking.

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

    bounds

    The element's box in the canvas' content space: the path's bounding box grown by padding.

    Declaration
    public Rect bounds { get; }
    Property Value
    Type Description
    Rect

    color

    An explicit stroke colour, overriding the stylesheet's.

    Declaration
    public Optional<Color> color { get; set; }
    Property Value
    Type Description
    Optional<Color>
    Remarks

    Unset by default, which is the normal case: the colour then comes from --edge-color and follows the theme. Set it only when the colour carries data, such as a connection type.

    curveStyle

    The path's shape. Bezier by default.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public CanvasCurveStyle curveStyle { get; set; }
    Property Value
    Type Description
    CanvasCurveStyle

    from

    The edge's start point, in the canvas' content space.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public Vector2 from { get; set; }
    Property Value
    Type Description
    Vector2

    highlighted

    Whether the edge is drawn emphasised, which is true when it is either active or selected.

    Declaration
    public bool highlighted { get; }
    Property Value
    Type Description
    bool

    isDirectional

    Whether an arrowhead is drawn at the path's midpoint. False by default.

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

    lod

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

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

    At Box, a far zoom-out, the edge draws its line only: no hit area and no arrow, which are too small to use at that scale. Compact draws like Full.

    midpoint

    Where the arrowhead sits, in the canvas' content space.

    Declaration
    public Vector2 midpoint { get; }
    Property Value
    Type Description
    Vector2

    midpointAngle

    The direction the arrowhead points, in degrees clockwise from the positive X axis.

    Declaration
    public float midpointAngle { get; }
    Property Value
    Type Description
    float

    resolvedColor

    The stroke colour resolved from the stylesheet.

    Declaration
    public Color resolvedColor { get; }
    Property Value
    Type Description
    Color

    resolvedHighlightColor

    The emphasised stroke colour resolved from the stylesheet.

    Declaration
    public Color resolvedHighlightColor { get; }
    Property Value
    Type Description
    Color

    sag

    How far a Cable edge droops at its middle, in pixels. Zero for every other curve style.

    Declaration
    public float sag { get; }
    Property Value
    Type Description
    float

    selected

    Whether the edge is selected. Drawn the same way as active.

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

    strokeWidth

    The stroke width in pixels. defaultStrokeWidth by default.

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

    A highlighted edge draws one pixel thicker, so it reads as emphasised at any width.

    to

    The edge's end point, in the canvas' content space.

    Declaration
    [CreateProperty]
    [UxmlAttribute]
    public Vector2 to { get; set; }
    Property Value
    Type Description
    Vector2

    Methods

    ContainsPoint(Vector2)

    Whether a point in the element's local space is close enough to the line to count as a hit.

    Declaration
    public override bool ContainsPoint(Vector2 localPoint)
    Parameters
    Type Name Description
    Vector2 localPoint

    The point, in the element's local coordinates.

    Returns
    Type Description
    bool

    Whether the point is within hitTolerance of the path.

    Overrides
    VisualElement.ContainsPoint(Vector2)

    GetCurveStyleUssClassName(CanvasCurveStyle)

    Declaration
    public static string GetCurveStyleUssClassName(CanvasCurveStyle enumValue)
    Parameters
    Type Name Description
    CanvasCurveStyle enumValue
    Returns
    Type Description
    string

    SamplePath()

    The path, sampled into a polyline in the canvas' content space.

    Declaration
    public IReadOnlyList<Vector2> SamplePath()
    Returns
    Type Description
    IReadOnlyList<Vector2>

    The sampled points, starting at from and ending at to.

    Remarks

    The same samples drive both painting and picking, so the line a user sees is exactly the line they can click.

    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

    selectRequested

    Raised when the edge is pressed.

    Declaration
    public event Action selectRequested
    Event Type
    Type Description
    Action

    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)