Unity's explanation of ARSessionAn AR scene should include anARSession
component. The AR Session controls the lifecycle of an AR experience by enabling or disabling AR on the target platform. TheARSession
can be on anyGameObject
.​​When you disable theARSession
, the system no longer tracks features in its environment, but if you enable it at a later time, the system will attempt to recover and maintain previously-detected features.If you enable the Attempt Update option, the device tries to install AR software if possible. Support for this feature is platform-dependent.Note: An AR session is a global construct. AnARSession
component manages this global session, so multipleARSession
components will all try to manage the same global session.Checking for device supportSome platforms might support a limited subset of devices. On these platforms, your application needs to be able to detect support for AR Foundation so it can provide an alternative experience when AR is not supported.TheARSession
component has a static coroutine that you can use to determine whether AR is supported at runtime:1public class MyComponent {2[SerializeField] ARSession m_Session;3​4IEnumerator Start() {5if ((ARSession.state == ARSessionState.None) ||6(ARSession.state == ARSessionState.CheckingAvailability))7{8yield return ARSession.CheckAvailability();9}10​11if (ARSession.state == ARSessionState.Unsupported)12{13// Start some fallback experience for unsupported devices14}15else16{17// Start the AR session18m_Session.enabled = true;19}20}21}Copied!Session stateTo determine the current state of the session (for example, whether the device is supported, if AR software is being installed, and whether the session is working), useARSession.state
. You can also subscribe to an event when the session state changes:ARSession.stateChanged
.
ARSessionState
None
Unsupported
CheckingAvailability
NeedsInstall
Installing
Ready
SessionInitialized
SessionTracking
AR Session Origin​​The purpose of theARSessionOrigin
is to transform trackable features, such as planar surfaces and feature points, into their final position, orientation, and scale in the Unity Scene. Because AR devices provide their data in "session space", which is an unscaled space relative to the beginning of the AR session, theARSessionOrigin
performs the appropriate transformation into Unity space.This concept is similar to the difference between "model" or "local" space and world space when working with other Assets in Unity. For instance, if you import a house Asset from a DCC tool, the door's position is relative to the modeler's origin. This is commonly called "model space" or "local space". When Unity instantiates it, it also has a world space that's relative to Unity's origin.Likewise, trackables that an AR device produces, such as planes, are provided in "session space", relative to the device's coordinate system. When instantiated in Unity asGameObject
s, they also have a world space. In order to instantiate them in the correct place, AR Foundation needs to know where the session origin should be in the Unity scene.ARSessionOrigin
also allows you to scale virtual content and apply an offset to the AR Camera. If you're scaling or offsetting theARSessionOrigin
, then its AR Camera should be a child of theARSessionOrigin
. Because the AR Camera is session-driven, this setup allows the AR Camera and detected trackables to move together.
git clone https://github.com/moetsi/Unity-DOTS-Multiplayer-XR-Sample/
git checkout 'Setting-Up-AR-Foundation'
‌