Version: 2021.1
USS Writing style sheets
Dispatching Events

The Event System

UI Toolkit includes an event system that communicates user interactions to visual elements. Inspired by HTML events, the UI Toolkit event system shares many of the same terminology and event naming. The event system is composed of the following:

  • Event dispatcher: The event system listens to events, coming from the operating system or scripts, and dispatches these events with the Event dispatcher. The Event dispatcher also determines the dispatching strategy used to send events to visual elements and other supporting classes.
  • Event handler: When an event occurs inside a panel, the event is sent to the VisualElement tree within the panel. You can add event handlers to visual elements to respond to certain event types when they occur. See Responding to events.
  • Event synthesizer: The operating system is not the only source of events. Scripts can also create and dispatch events through the dispatcher. See Synthesizing Events for more on creating and dispatching events.
  • Event types: The different event types are organized into a hierarchy based on EventBase and grouped into families. Each family of events implements an interface that defines the common characteristics for all events of the same family. For example, MouseUpEvent, MouseDownEvent and other mouse events implement the IMouseEvent inteface. This interface specifies that each mouse event has a position, a pressed button, a set of modifers, and other mouse-related event types. See Event type reference for a description of each event family and their UIElement event types.

You can also use events to communicate other types of messages to visual elements. For example, the ContextualMenuManager uses the ContextualMenuPopulateEvent to add items to a contextual menu. See built-in controls.


  • 2018–11–02 Page amended
USS Writing style sheets
Dispatching Events
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961