Version: Unity 6.3 Beta (6000.3)
LanguageEnglish
  • C#

UIDocument

class in UnityEngine.UIElements

/

Inherits from:MonoBehaviour

/

Implemented in:UnityEngine.UIElementsModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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!"; } } }

Properties

Property Description
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.
pivot Defines the pivot point for positioning and transformation, such as rotation and scaling, of the UI Document in world space. The default pivot is the center.
pivotReferenceSize Defines how the size of the container is calculated for pivot positioning.
position The position (relative or absolute) of the root visual element. Relative only applies for nested UIDocuments.
rootVisualElement The root visual element where the UI hierarchy starts.
runtimePanel The runtime panel whose visualTree contains this document's rootVisualElement, if any.
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.
worldSpaceSize When the worldSpaceSizeMode is set to WorldSpaceSizeMode.Fixed, this property determines the size of the UIDocument in world space.
worldSpaceSizeMode Defines how the size of the root element is calculated for world space.

Inherited Members

Properties

PropertyDescription
enabledEnabled Behaviours are Updated, disabled Behaviours are not.
isActiveAndEnabledChecks whether a component is enabled, attached to a GameObject that is active in the hierarchy, and the component's OnEnable has been called.
gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
transformHandleThe TransformHandle of this GameObject.
destroyCancellationTokenCancellation token raised when the MonoBehaviour is destroyed (Read Only).
didAwakeReturns a boolean value which represents if Awake was called.
didStartReturns a boolean value which represents if Start was called.
runInEditModeAllow a specific instance of a MonoBehaviour to run in edit mode (only available in the editor).
useGUILayoutDisabling this lets you skip the GUI layout phase.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

MethodDescription
BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentGets a reference to a component of type T on the same GameObject as the component specified.
GetComponentInChildrenGets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject.
GetComponentIndexGets the index of the component on its parent GameObject.
GetComponentInParentGets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject.
GetComponentsGets references to all components of type T on the same GameObject as the component specified.
GetComponentsInChildrenGets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject.
GetComponentsInParentGets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
TryGetComponentGets the component of the specified type, if it exists.
CancelInvokeCancels all Invoke calls on this MonoBehaviour.
InvokeInvokes the method methodName in time seconds.
InvokeRepeatingInvokes the specified method after a specified delay, then repeatedly at the specified rate.
IsInvokingIs any invoke on methodName pending?
StartCoroutineStarts a coroutine.
StopAllCoroutinesStops all coroutines running on this MonoBehaviour.
StopCoroutineStops the first coroutine named methodName, or the coroutine stored in routine running on this behaviour.
GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.

Static Methods

MethodDescription
printLogs a message to the Unity Console. Functionally equivalent to Debug.Log.
DestroyRemoves a GameObject, component, or asset.
DestroyImmediateDestroys the specified object immediately. Use with caution and in Edit mode only.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.
InstantiateAsyncCaptures a snapshot of the original object (that must be related to some GameObject) and returns the AsyncInstantiateOperation.

Operators

OperatorDescription
boolDoes 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.

Messages

MessageDescription
AwakeUnity calls Awake when loading an instance of a script component.
FixedUpdateUpdate called at regular, fixed intervals as part of Unity's physics update loop.
LateUpdateLateUpdate is called every frame, if the Behaviour is enabled.
OnAnimatorIKCallback for setting up animation IK (inverse kinematics).
OnAnimatorMoveCallback for processing animation movements for modifying root motion.
OnApplicationFocusSent to all GameObjects when the player gets or loses focus.
OnApplicationPauseSent to all GameObjects when the playing application pauses or resumes on losing or regaining focus.
OnApplicationQuitSent to all GameObjects before the application quits.
OnAudioFilterReadIf OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain.
OnBecameInvisibleCalled when the renderer is no longer visible to any camera.
OnBecameVisibleCalled when the renderer becomes visible to any camera.
OnCollisionEnterOnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
OnCollisionEnter2DSent when an incoming collider makes contact with this object's collider (2D physics only).
OnCollisionExitOnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
OnCollisionExit2DSent when a collider on another object stops touching this object's collider (2D physics only).
OnCollisionStayOnCollisionStay is called once per frame for every Collider or Rigidbody that touches another Collider or Rigidbody.
OnCollisionStay2DSent each frame where a collider on another object is touching this object's collider (2D physics only).
OnControllerColliderHitOnControllerColliderHit is called when the CharacterController component hits a collider while performing a Move.
OnDestroyCalled when a GameObject or component is about to be destroyed.
OnDisableCalled when a component itself is disabled or its parent GameObject is deactivated.
OnDrawGizmosImplement OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn.
OnDrawGizmosSelectedImplement OnDrawGizmosSelected to draw a gizmo if the object is selected.
OnEnableCalled when a component of an active GameObject is first enabled.
OnGUIOnGUI is called for rendering and handling GUI events.
OnJointBreakCalled when a joint attached to the same game object broke.
OnJointBreak2DCalled 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.
OnMouseDragOnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse.
OnMouseEnterCalled when the mouse enters the Collider.
OnMouseExitCalled when the mouse is not any longer over the Collider.
OnMouseOverCalled every frame while the mouse is over the Collider.
OnMouseUpCalled on releasing the mouse button while the mouse pointer is over the Collider attached to this GameObject.
OnMouseUpAsButtonOnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed.
OnParticleCollisionOnParticleCollision is called when a particle hits a Collider.
OnParticleSystemStoppedOnParticleSystemStopped 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.
OnParticleTriggerOnParticleTrigger is called when any particles in a Particle System meet the conditions in the trigger module.
OnParticleUpdateJobScheduledOnParticleUpdateJobScheduled 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.
OnRenderObjectOnRenderObject is called after camera has rendered the Scene.
OnTransformChildrenChangedCalled when the list of direct children of a GameObject's Transform changes.
OnTransformParentChangedCalled when a direct or indirect parent of a GameObject's Transform changes.
OnTriggerEnterCalled when a collider enters a trigger collider.
OnTriggerEnter2DSent when another object enters a trigger collider attached to this object (2D physics only).
OnTriggerExitOnTriggerExit is called when a collider stops touching a trigger.
OnTriggerExit2DSent when another object leaves a trigger collider attached to this object (2D physics only).
OnTriggerStayCalled once per physics update for every collider that is touching the trigger.
OnTriggerStay2DSent once per physics update when another object is within a trigger collider attached to this object (2D physics only).
OnValidateEditor-only function that Unity calls when the script is loaded or a value changes in the Inspector.
OnWillRenderObjectCalled for each camera if the object is visible and not a UI element.
ResetReset a component to default values.
StartStart is called on the frame when a script is enabled just before any of the Update methods are called the first time.
UpdateUpdate is called every frame, if the MonoBehaviour is enabled.