Shared Spatial Anchors Health and Safety Sample App for Unity
Health & Safety Recommendation: While building mixed reality experiences with the Passthrough API, we highly recommend that developers evaluate their content to support a comfortable and safe experience for users. Refer to the
Mixed Reality Design Guidelines topic for more information.
Unity-SharedSpatialAnchors Health & Safety was built to demonstrate how to use the Shared Spatial Anchors API, available in the
Meta XR Core SDK for the Unity game engine. The sample app showcases the creation, saving, loading, and sharing of Spatial Anchors.
For anchor sharing, this app uses Photon Unity Networking to share player data and also allows users to interact with networked objects in a co-located space.
This codebase is available both as a reference and as a template for a game that utilizes Shared Spatial Anchors. Unity-SharedSpatialAnchors is under the license found
here unless otherwise specified.
Set up Project Environment
This project uses Photon’s PUN to support multiplayer networking. Create an account on the
Photon site.
You will need to create a PUN app on your developer account and add the app ID to the PhotonServerSettings file at Assets/Photon/PhotonUnityNetworking/Resources/PhotonServerSettings, under the entry AppIdRealtime. You can find the PhotonServerSettings from the menu at Window > Photon Unity Networking > Highlight Server Settings.
Steps for creating a new Photon application are:
- Photon Type - Set to PUN
- Name and Description - can be set to anything
- URL - can be left blank
Upon joining the scene you should be in a passthrough environment, with virtual representations of your right and left controllers.
A control panel follows your left controller. You can use your right controller to interact with it. Buttons on the menu are physically pressed by pushing against it with the white dot on your controller.
Create or join a room using the control panel to get started. The main menu is comprised of the following:
- Change User Visual: This updates the Passthrough Avatar visual mode.
- Always Passthrough
- Distance Passthrough
- Momentum Passthrough
- None
- Photon Info Panel: Shows the photon room that the player has connected to, the current status of connection, and a list of users in the room.
- Logging Panel: The right half of the menu is used for logging (for debug purposes). You can press the arrow buttons on the bottom right to navigate multiple pages of logs.
As with all features—experimental or otherwise—developers should take care to evaluate their apps’ design and content to support a comfortable and safe experience for users. Please refer to the design best practices available in the
Developer Hub (see the Design section) and the
Health & Safety Information applicable to the VR system that your app is designed for.
- The offered components reduce the risk during co-located experiences
This demo supports automatic anchor creation, alignment, and sharing. When two users join the same room, they are automatically colocated and placed in a VR environment with passthrough avatars.
The Directional Passthrough is specifically useful for cueing users to other co-located users in their periphery that is blocked by the restricted headset field of view and is a default part of the sample. The sample documentation shows Passthrough used as a cue for a user in an immersive VR experience. However, this can be adapted for Passthrough based experiences by having the peripheral cue appear as coloured virtual content, for example, a band of red instead of Passthrough.
The Segmented Passthrough applies a cutout to other co-located users (Passthrough Avatar). The cutout is wider than the avatar to account for pose mis-estimation and extends to include the lower body. The User Visual updates the Passthrough Avatar visual mode to have the Passthrough constant (Always Passthrough) or triggered by proximity (Distance Passthrough, shown below) and/or relative speed (Momentum Passthrough).
The
Passthrough API provides real-time visualization of the physical world while in VR:
If the spatial mapping of the avatar to the user’s physical position is not aligned, issues arise with the mismatch between visual and auditory information. However, a combination of Directional and Segmented Passthrough could be employed as a mechanism to warn users of the physical position of other co-located users.
The Unity scene is available at Assets/CoLocation/Scenes/CoLocatedSafety.unity.
The following scene hierarchy is applied:
ControlPanel - World-space UI for creating / joining rooms and changing the user visual
PhotonNetworkManager - Networking Manager for Photon rooms, player synchronization, and shared anchor ID sharing.
AlignPlayer - Transforms the anchors position from world-space to local-space and applies orientation to the OVRCameraRig
CoLocatedPassthroughManager - Manages passthrough objects attached to the camera rig. There is support for multiple passthrough avatar types:
- Always Passthrough
- Distance Passthrough
- Momentum Passthrough
- None
OVRCameraRig - The tracking space with OVR camera and hand components as children
- CoLocatedPassthroughManager
- CoLocPassthroughAvatar
- DirectionalPassthrough
- Hand
- Head
- AvatarPassthrough
- CoLocatedPassthroughManager
- DirectionalPassthrough
- PassthroughAvatarPhoton
- SoftPassthroughDot