class in UnityEngine.UIElements
/
Inherits from:MonoBehaviour
/
Implemented in:UnityEngine.UIElementsModule
Defines a Component that connects VisualElements to GameObjects.
This makes it possible to render UI defined in UXML documents in the Game view.
The following example shows how to query a UIDocument component and interact with its elements.
using UnityEngine; using UnityEngine.UIElements;
public class UIDocument_Example : MonoBehaviour { // Configured via the inspector public UIDocument document;
void OnEnable() { // Expects a button with the name "my-button" to be present in the UXML. // If it doesn't exist, create it. var button = document.rootVisualElement.Q<Button>("my-button"); if (button == null) { button = new Button { name = "my-button", text = "Click me!" }; document.rootVisualElement.Add(button); }
button.clicked += ButtonClicked; }
void ButtonClicked() { var label = document.rootVisualElement.Q<Label>("my-label");
// Add a label if it doesn't exist if (label == null) { label = new Label { name = "my-label", text = "Button clicked!" }; document.rootVisualElement.Add(label); } else { label.text = "Button clicked!"; } } }
panelSettings | Specifies the PanelSettings instance to connect this UIDocument component to. |
parentUI | If the GameObject that this UIDocument component is attached to has a parent GameObject, and that parent GameObject also has a UIDocument component attached to it, this value is set to the parent GameObject's UIDocument component automatically. |
rootVisualElement | The root visual element where the UI hierarchy starts. |
runtimePanel | The runtime panel that this UIDocument is attached to. |
sortingOrder | The order in which this UIDocument will show up on the hierarchy in relation to other UIDocuments either attached to the same PanelSettings, or with the same UIDocument parent. |
visualTreeAsset | The VisualTreeAsset loaded into the root visual element automatically. |
enabled | Enabled Behaviours are Updated, disabled Behaviours are not. |
isActiveAndEnabled | Reports whether a GameObject and its associated Behaviour is active and enabled. |
gameObject | The game object this component is attached to. A component is always attached to a game object. |
tag | The tag of this game object. |
transform | The Transform attached to this GameObject. |
destroyCancellationToken | Cancellation token raised when the MonoBehaviour is destroyed (Read Only). |
didAwake | Returns a boolean value which represents if Awake was called. |
didStart | Returns a boolean value which represents if Start was called. |
runInEditMode | Allow a specific instance of a MonoBehaviour to run in edit mode (only available in the editor). |
useGUILayout | Disabling this lets you skip the GUI layout phase. |
hideFlags | Should the object be hidden, saved with the Scene or modifiable by the user? |
name | The name of the object. |
BroadcastMessage | Calls the method named methodName on every MonoBehaviour in this game object or any of its children. |
CompareTag | Checks the GameObject's tag against the defined tag. |
GetComponent | Gets a reference to a component of type T on the same GameObject as the component specified. |
GetComponentInChildren | Gets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject. |
GetComponentIndex | Gets the index of the component on its parent GameObject. |
GetComponentInParent | Gets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject. |
GetComponents | Gets references to all components of type T on the same GameObject as the component specified. |
GetComponentsInChildren | Gets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject. |
GetComponentsInParent | Gets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject. |
SendMessage | Calls the method named methodName on every MonoBehaviour in this game object. |
SendMessageUpwards | Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour. |
TryGetComponent | Gets the component of the specified type, if it exists. |
CancelInvoke | Cancels all Invoke calls on this MonoBehaviour. |
Invoke | Invokes the method methodName in time seconds. |
InvokeRepeating | Invokes the method methodName in time seconds, then repeatedly every repeatRate seconds. |
IsInvoking | Is any invoke on methodName pending? |
StartCoroutine | Starts a Coroutine. |
StopAllCoroutines | Stops all coroutines running on this behaviour. |
StopCoroutine | Stops the first coroutine named methodName, or the coroutine stored in routine running on this behaviour. |
GetInstanceID | Gets the instance ID of the object. |
ToString | Returns the name of the object. |
Logs message to the Unity Console (identical to Debug.Log). | |
Destroy | Removes a GameObject, component or asset. |
DestroyImmediate | Destroys the object obj immediately. You are strongly recommended to use Destroy instead. |
DontDestroyOnLoad | Do not destroy the target Object when loading a new Scene. |
FindAnyObjectByType | Retrieves any active loaded object of Type type. |
FindFirstObjectByType | Retrieves the first active loaded object of Type type. |
FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
Instantiate | Clones the object original and returns the clone. |
InstantiateAsync | Captures a snapshot of the original object (that must be related to some GameObject) and returns the AsyncInstantiateOperation. |
bool | Does the object exist? |
operator != | Compares if two objects refer to a different object. |
operator == | Compares two object references to see if they refer to the same object. |
Awake | Unity calls Awake when an enabled script instance is being loaded. |
FixedUpdate | Frame-rate independent MonoBehaviour.FixedUpdate message for physics calculations. |
LateUpdate | LateUpdate is called every frame, if the Behaviour is enabled. |
OnAnimatorIK | Callback for setting up animation IK (inverse kinematics). |
OnAnimatorMove | Callback for processing animation movements for modifying root motion. |
OnApplicationFocus | Sent to all GameObjects when the player gets or loses focus. |
OnApplicationPause | Sent to all GameObjects when the playing application pauses or resumes on losing or regaining focus. |
OnApplicationQuit | Sent to all GameObjects before the application quits. |
OnAudioFilterRead | If OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain. |
OnBecameInvisible | OnBecameInvisible is called when the renderer is no longer visible by any camera. |
OnBecameVisible | OnBecameVisible is called when the renderer became visible by any camera. |
OnCollisionEnter | OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider. |
OnCollisionEnter2D | Sent when an incoming collider makes contact with this object's collider (2D physics only). |
OnCollisionExit | OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider. |
OnCollisionExit2D | Sent when a collider on another object stops touching this object's collider (2D physics only). |
OnCollisionStay | OnCollisionStay is called once per frame for every Collider or Rigidbody that touches another Collider or Rigidbody. |
OnCollisionStay2D | Sent each frame where a collider on another object is touching this object's collider (2D physics only). |
OnConnectedToServer | Called on the client when you have successfully connected to a server. |
OnControllerColliderHit | OnControllerColliderHit is called when the controller hits a collider while performing a Move. |
OnDestroy | Destroying the attached Behaviour will result in the game or Scene receiving OnDestroy. |
OnDisable | This function is called when the behaviour becomes disabled. |
OnDrawGizmos | Implement OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn. |
OnDrawGizmosSelected | Implement OnDrawGizmosSelected to draw a gizmo if the object is selected. |
OnEnable | This function is called when the object becomes enabled and active. |
OnFailedToConnect | Called on the client when a connection attempt fails for some reason. |
OnGUI | OnGUI is called for rendering and handling GUI events. |
OnJointBreak | Called when a joint attached to the same game object broke. |
OnJointBreak2D | Called when a Joint2D attached to the same game object breaks. |
OnMouseDown | OnMouseDown is called when the user presses the left mouse button while over the Collider. |
OnMouseDrag | OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse. |
OnMouseEnter | Called when the mouse enters the Collider. |
OnMouseExit | Called when the mouse is not any longer over the Collider. |
OnMouseOver | Called every frame while the mouse is over the Collider. |
OnMouseUp | OnMouseUp is called when the user has released the mouse button. |
OnMouseUpAsButton | OnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed. |
OnParticleCollision | OnParticleCollision is called when a particle hits a Collider. |
OnParticleSystemStopped | OnParticleSystemStopped is called when all particles in the system have died, and no new particles will be born. New particles cease to be created either after Stop is called, or when the duration property of a non-looping system has been exceeded. |
OnParticleTrigger | OnParticleTrigger is called when any particles in a Particle System meet the conditions in the trigger module. |
OnParticleUpdateJobScheduled | OnParticleUpdateJobScheduled is called when a Particle System's built-in update job has been scheduled. |
OnPostRender | Event function that Unity calls after a Camera renders the scene. |
OnPreCull | Event function that Unity calls before a Camera culls the scene. |
OnPreRender | Event function that Unity calls before a Camera renders the scene. |
OnRenderImage | Event function that Unity calls after a Camera has finished rendering, that allows you to modify the Camera's final image. |
OnRenderObject | OnRenderObject is called after camera has rendered the Scene. |
OnServerInitialized | Called on the server whenever a Network.InitializeServer was invoked and has completed. |
OnTransformChildrenChanged | This function is called when the list of children of the transform of the GameObject has changed. |
OnTransformParentChanged | This function is called when a direct or indirect parent of the transform of the GameObject has changed. |
OnTriggerEnter | When a GameObject collides with another GameObject, Unity calls OnTriggerEnter. |
OnTriggerEnter2D | Sent when another object enters a trigger collider attached to this object (2D physics only). |
OnTriggerExit | OnTriggerExit is called when the Collider other has stopped touching the trigger. |
OnTriggerExit2D | Sent when another object leaves a trigger collider attached to this object (2D physics only). |
OnTriggerStay | OnTriggerStay is called once per physics update for every Collider other that is touching the trigger. |
OnTriggerStay2D | Sent once per physics update when another object is within a trigger collider attached to this object (2D physics only). |
OnValidate | Editor-only function that Unity calls when the script is loaded or a value changes in the Inspector. |
OnWillRenderObject | OnWillRenderObject is called for each camera if the object is visible and not a UI element. |
Reset | Reset to default values. |
Start | Start is called on the frame when a script is enabled just before any of the Update methods are called the first time. |
Update | Update is called every frame, if the MonoBehaviour is enabled. |