trackScreenSpacePosition
Whether the root visual element follows the position of the GameObject in screen space. The default value is false.
Read time 1 minuteLast updated 10 days ago
Definition
- Type: Property
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
public bool trackScreenSpacePosition { get; set; }
Remarks
Only takes effect in screen-space render modes. Ignored in PanelRenderMode.WorldSpace.
While enabled, the root visual element is sized by its content and the renderer controls its and inline styles: every frame, the root is translated so its origin matches the position of the GameObject on screen, as seen from the main camera. When that position is not on screen, the root is hidden. When there is no main camera, the last tracked styles are kept.
translatedisplayUse this, for example, for a screen-space health bar that follows a unit moving in the 3D world. Use _screenSpaceOffset to offset the UI from the tracked position.