docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ConfirmDialog

    A two-choice confirmation dialog, and the imperative helper that shows one and awaits the answer.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    BaseDialog
    AlertDialog
    ConfirmDialog
    Implements
    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder
    IDismissInvocator
    Inherited Members
    AlertDialog.primaryActionUssClassName
    AlertDialog.secondaryActionUssClassName
    AlertDialog.cancelActionUssClassName
    AlertDialog.iconUssClassName
    AlertDialog.primaryButton
    AlertDialog.secondaryButton
    AlertDialog.cancelButton
    AlertDialog.variant
    AlertDialog.isPrimaryActionDisabled
    AlertDialog.isSecondaryActionDisabled
    AlertDialog.dismissRequested
    AlertDialog.SetPrimaryAction(int, string, Action)
    AlertDialog.SetSecondaryAction(int, string, Action)
    AlertDialog.SetCancelAction(int, string)
    BaseDialog.ussClassName
    BaseDialog.variantUssClassName
    BaseDialog.sizeUssClassName
    BaseDialog.headingUssClassName
    BaseDialog.headerUssClassName
    BaseDialog.dividerUssClassName
    BaseDialog.contentUssClassName
    BaseDialog.buttonGroupUssClassName
    BaseDialog.m_ActionContainer
    BaseDialog.m_Content
    BaseDialog.m_Divider
    BaseDialog.m_Header
    BaseDialog.m_Heading
    BaseDialog.contentContainer
    BaseDialog.actionContainer
    BaseDialog.title
    BaseDialog.ShouldHideHeading()
    BaseDialog.RefreshHeading()
    BaseDialog.description
    BaseDialog.size
    BaseDialog.GetSizeUssClassName(DialogSize)
    BaseDialog.GetVariantUssClassName(AlertSemantic)
    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 ConfirmDialog : AlertDialog, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IDismissInvocator
    Remarks

    ConfirmDialog is the ergonomic layer over AlertDialog and Modal: instead of wiring a primary action, a cancel action and a modal by hand every time you need a yes/no answer, you call Show(VisualElement, string, string, string, string, bool) and await a Task<TResult> of bool.

    The task completes true when the user takes the confirm action and false for every other outcome: the cancel action, the escape key, or a click outside the modal. It resolves exactly once, so a dismiss that follows a confirm cannot flip the answer.

    Concurrent calls queue. Only one confirmation is on screen at a time and the next one is shown as soon as the current one closes, so a loop over several items does not stack a pile of modals on top of each other.

    ConfirmDelete(VisualElement, string, int) is the preset for the common destructive case. It frames the dialog with the Destructive semantic, labels the confirm action "Delete" and adds the "This action cannot be undone." description.

    The element itself is a normal AlertDialog subclass, so it can also be declared in UXML and driven manually through Confirm() and Cancel().

    Examples

    Awaiting a confirmation before running a destructive action.

    async void OnDeleteClicked()
    {
        if (await ConfirmDialog.ConfirmDelete(rootElement, selection.name))
            DeleteSelection();
    }

    A custom confirmation with its own labels.

    var confirmed = await ConfirmDialog.Show(
        rootElement,
        title: "Discard changes?",
        description: "Your edits to this scene will be lost.",
        confirmLabel: "Discard",
        cancelLabel: "Keep editing",
        destructive: true);

    Declaring the dialog in UXML and showing it yourself.

    <UXML>
    <appui:ConfirmDialog
        title="Delete asset?"
        description="This action cannot be undone."
        confirm-label="Delete"
        cancel-label="Cancel"
        destructive="true" />
    </UXML>

    Constructors

    ConfirmDialog()

    Default constructor.

    Declaration
    public ConfirmDialog()

    Fields

    confirmUssClassName

    The main styling class of the ConfirmDialog. This is the class that is used to style the element in addition to the ussClassName class.

    Declaration
    public const string confirmUssClassName = "appui-confirm-dialog"
    Field Value
    Type Description
    string

    defaultCancelLabel

    The default label of the cancel action.

    Declaration
    public const string defaultCancelLabel = "Cancel"
    Field Value
    Type Description
    string

    defaultConfirmLabel

    The default label of the confirm action.

    Declaration
    public const string defaultConfirmLabel = "Confirm"
    Field Value
    Type Description
    string

    deleteDescription

    The description used by ConfirmDelete(VisualElement, string, int).

    Declaration
    public const string deleteDescription = "This action cannot be undone."
    Field Value
    Type Description
    string

    destructiveUssClassName

    The styling class applied when destructive is true.

    Declaration
    public const string destructiveUssClassName = "appui-confirm-dialog--destructive"
    Field Value
    Type Description
    string

    Properties

    cancelLabel

    The label of the cancel action. Defaults to defaultCancelLabel.

    Declaration
    [Tooltip("The label of the cancel action.")]
    [CreateProperty]
    [UxmlAttribute]
    public string cancelLabel { get; set; }
    Property Value
    Type Description
    string

    confirmLabel

    The label of the confirm action. Defaults to defaultConfirmLabel.

    Declaration
    [Tooltip("The label of the confirm action.")]
    [CreateProperty]
    [UxmlAttribute]
    [Header("Confirm Dialog")]
    public string confirmLabel { get; set; }
    Property Value
    Type Description
    string

    confirmed

    The task that completes with the user's answer: true when the confirm action is taken, false for a cancel, an escape key press or an outside click. It resolves exactly once.

    Declaration
    public Task<bool> confirmed { get; }
    Property Value
    Type Description
    Task<bool>

    destructive

    Frames the confirmation as destructive: the dialog takes the Destructive semantic and the confirm action becomes a Destructive button.

    Declaration
    [Tooltip("Frames the confirmation as destructive.")]
    [CreateProperty]
    [UxmlAttribute]
    public bool destructive { get; set; }
    Property Value
    Type Description
    bool

    Methods

    BuildDelete(string, int)

    Build an unshown ConfirmDialog configured as a delete confirmation.

    Declaration
    public static ConfirmDialog BuildDelete(string what, int count = 1)
    Parameters
    Type Name Description
    string what

    Names the thing being deleted — an object's name, or a plural noun such as "objects" when deleting several.

    int count

    How many things are being deleted. Above one the title reads "Delete N <what>?".

    Returns
    Type Description
    ConfirmDialog

    The configured dialog.

    Cancel()

    Resolve confirmed with false. Called by the cancel action and by any dismissal; safe to call more than once, later calls are ignored.

    Declaration
    public void Cancel()

    Confirm()

    Resolve confirmed with true. Called by the confirm action; safe to call more than once, later calls are ignored.

    Declaration
    public void Confirm()

    ConfirmDelete(VisualElement, string, int)

    Show a delete confirmation and await the user's answer. The destructive preset of Show(VisualElement, string, string, string, string, bool).

    Declaration
    public static Task<bool> ConfirmDelete(VisualElement referenceView, string what, int count = 1)
    Parameters
    Type Name Description
    VisualElement referenceView

    Any VisualElement currently in the UI panel that should host the modal.

    string what

    Names the thing being deleted.

    int count

    How many things are being deleted.

    Returns
    Type Description
    Task<bool>

    A task that completes true when confirmed, false otherwise.

    Show(VisualElement, string, string, string, string, bool)

    Show a confirmation dialog and await the user's answer.

    Declaration
    public static Task<bool> Show(VisualElement referenceView, string title, string description = null, string confirmLabel = null, string cancelLabel = null, bool destructive = false)
    Parameters
    Type Name Description
    VisualElement referenceView

    Any VisualElement currently in the UI panel that should host the modal.

    string title

    The dialog title.

    string description

    An optional supporting line under the title.

    string confirmLabel

    The confirm action's label. Defaults to "Confirm".

    string cancelLabel

    The cancel action's label. Defaults to "Cancel".

    bool destructive

    Frames the confirmation as destructive.

    Returns
    Type Description
    Task<bool>

    A task that completes true when confirmed, false otherwise.

    Exceptions
    Type Condition
    ArgumentNullException

    If referenceView is null.

    Show(VisualElement, ConfirmDialog)

    Show an already configured ConfirmDialog and await the user's answer.

    Declaration
    public static Task<bool> Show(VisualElement referenceView, ConfirmDialog dialog)
    Parameters
    Type Name Description
    VisualElement referenceView

    Any VisualElement currently in the UI panel that should host the modal.

    ConfirmDialog dialog

    The dialog to show.

    Returns
    Type Description
    Task<bool>

    A task that completes true when confirmed, false otherwise.

    Exceptions
    Type Condition
    ArgumentNullException

    If referenceView or dialog is null.

    Implements

    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder
    IDismissInvocator

    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)