User Interface
To interact with User Interfaces (UI) in Virtual Reality it's necessary that the components are configured to work in this mode. This articles explains how to set up user interfaces that work both in Desktop and VR modes.
Set up the canvas GameObject
To create a UI create a GameObject with the Canvas component. All the objects that make up the interface (such as buttons and images) will be organized within this GameObject's hierarchy. These are the elements that need to be in that root GameObject:
- Canvas: Unity´s component. Unlike standard UI canvases in
Screen Space
, XR Interaction Toolkit requires aWorld Space
Canvas. This positions the UI elements in the 3D world, allowing users to interact with them in VR and Desktop. - Tracked Device Graphic Raycaster: This component is crucial for XR Interaction Toolkit UI interaction. With this, controllers (via Near-Far Interactor) or gaze (via XR Gaze Interactor) cast rays and detect UI elements in the World Space Canvas.
- Graphic Raycaster: To interact with UI in Desktop mode.
Tip
If you want to create a UI that doesn't require interaction, the GraphicRaycaster and TrackedDeviceGraphicRaycaster components aren't necessary.