docs.unity3d.com
    Show / Hide Table of Contents

    Class ARSession

    Controls the lifecycle and configuration options for an AR session. There is only one active session. If you have multiple ARSession components, they all communicate to the same session and will conflict with each other.

    Enabling or disabling the ARSession starts or stops the session, respectively.

    Inheritance
    Object
    UnityEngine.Object
    UnityEngine.Component
    UnityEngine.Behaviour
    UnityEngine.MonoBehaviour
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>
    ARSession
    Inherited Members
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.subsystem
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.descriptor
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.GetActiveSubsystemInstance()
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.EnsureSubsystemInstanceSet()
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.OnEnable()
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.OnDisable()
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.OnDestroy()
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.OnBeforeStart()
    SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>.OnAfterStart()
    UnityEngine.MonoBehaviour.IsInvoking()
    UnityEngine.MonoBehaviour.CancelInvoke()
    UnityEngine.MonoBehaviour.Invoke(System.String, System.Single)
    UnityEngine.MonoBehaviour.InvokeRepeating(System.String, System.Single, System.Single)
    UnityEngine.MonoBehaviour.CancelInvoke(System.String)
    UnityEngine.MonoBehaviour.IsInvoking(System.String)
    UnityEngine.MonoBehaviour.StartCoroutine(System.String)
    UnityEngine.MonoBehaviour.StartCoroutine(System.String, System.Object)
    UnityEngine.MonoBehaviour.StartCoroutine(System.Collections.IEnumerator)
    UnityEngine.MonoBehaviour.StartCoroutine_Auto(System.Collections.IEnumerator)
    UnityEngine.MonoBehaviour.StopCoroutine(System.Collections.IEnumerator)
    UnityEngine.MonoBehaviour.StopCoroutine(UnityEngine.Coroutine)
    UnityEngine.MonoBehaviour.StopCoroutine(System.String)
    UnityEngine.MonoBehaviour.StopAllCoroutines()
    UnityEngine.MonoBehaviour.print(System.Object)
    UnityEngine.MonoBehaviour.useGUILayout
    UnityEngine.MonoBehaviour.runInEditMode
    UnityEngine.Behaviour.enabled
    UnityEngine.Behaviour.isActiveAndEnabled
    UnityEngine.Component.GetComponent(System.Type)
    UnityEngine.Component.GetComponent<T>()
    UnityEngine.Component.TryGetComponent(System.Type, UnityEngine.Component)
    UnityEngine.Component.TryGetComponent<T>(T)
    UnityEngine.Component.GetComponent(System.String)
    UnityEngine.Component.GetComponentInChildren(System.Type, System.Boolean)
    UnityEngine.Component.GetComponentInChildren(System.Type)
    UnityEngine.Component.GetComponentInChildren<T>(System.Boolean)
    UnityEngine.Component.GetComponentInChildren<T>()
    UnityEngine.Component.GetComponentsInChildren(System.Type, System.Boolean)
    UnityEngine.Component.GetComponentsInChildren(System.Type)
    UnityEngine.Component.GetComponentsInChildren<T>(System.Boolean)
    UnityEngine.Component.GetComponentsInChildren<T>(System.Boolean, System.Collections.Generic.List<T>)
    UnityEngine.Component.GetComponentsInChildren<T>()
    UnityEngine.Component.GetComponentsInChildren<T>(System.Collections.Generic.List<T>)
    UnityEngine.Component.GetComponentInParent(System.Type, System.Boolean)
    UnityEngine.Component.GetComponentInParent(System.Type)
    UnityEngine.Component.GetComponentInParent<T>(System.Boolean)
    UnityEngine.Component.GetComponentInParent<T>()
    UnityEngine.Component.GetComponentsInParent(System.Type, System.Boolean)
    UnityEngine.Component.GetComponentsInParent(System.Type)
    UnityEngine.Component.GetComponentsInParent<T>(System.Boolean)
    UnityEngine.Component.GetComponentsInParent<T>(System.Boolean, System.Collections.Generic.List<T>)
    UnityEngine.Component.GetComponentsInParent<T>()
    UnityEngine.Component.GetComponents(System.Type)
    UnityEngine.Component.GetComponents(System.Type, System.Collections.Generic.List<UnityEngine.Component>)
    UnityEngine.Component.GetComponents<T>(System.Collections.Generic.List<T>)
    UnityEngine.Component.GetComponents<T>()
    UnityEngine.Component.CompareTag(System.String)
    UnityEngine.Component.SendMessageUpwards(System.String, System.Object, UnityEngine.SendMessageOptions)
    UnityEngine.Component.SendMessageUpwards(System.String, System.Object)
    UnityEngine.Component.SendMessageUpwards(System.String)
    UnityEngine.Component.SendMessageUpwards(System.String, UnityEngine.SendMessageOptions)
    UnityEngine.Component.SendMessage(System.String, System.Object)
    UnityEngine.Component.SendMessage(System.String)
    UnityEngine.Component.SendMessage(System.String, System.Object, UnityEngine.SendMessageOptions)
    UnityEngine.Component.SendMessage(System.String, UnityEngine.SendMessageOptions)
    UnityEngine.Component.BroadcastMessage(System.String, System.Object, UnityEngine.SendMessageOptions)
    UnityEngine.Component.BroadcastMessage(System.String, System.Object)
    UnityEngine.Component.BroadcastMessage(System.String)
    UnityEngine.Component.BroadcastMessage(System.String, UnityEngine.SendMessageOptions)
    UnityEngine.Component.transform
    UnityEngine.Component.gameObject
    UnityEngine.Component.tag
    UnityEngine.Object.GetInstanceID()
    UnityEngine.Object.GetHashCode()
    UnityEngine.Object.Equals(System.Object)
    UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)
    UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion, UnityEngine.Transform)
    UnityEngine.Object.Instantiate(UnityEngine.Object)
    UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Transform)
    UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Transform, System.Boolean)
    UnityEngine.Object.Instantiate<T>(T)
    UnityEngine.Object.Instantiate<T>(T, UnityEngine.Vector3, UnityEngine.Quaternion)
    UnityEngine.Object.Instantiate<T>(T, UnityEngine.Vector3, UnityEngine.Quaternion, UnityEngine.Transform)
    UnityEngine.Object.Instantiate<T>(T, UnityEngine.Transform)
    UnityEngine.Object.Instantiate<T>(T, UnityEngine.Transform, System.Boolean)
    UnityEngine.Object.Destroy(UnityEngine.Object, System.Single)
    UnityEngine.Object.Destroy(UnityEngine.Object)
    UnityEngine.Object.DestroyImmediate(UnityEngine.Object, System.Boolean)
    UnityEngine.Object.DestroyImmediate(UnityEngine.Object)
    UnityEngine.Object.FindObjectsOfType(System.Type)
    UnityEngine.Object.FindObjectsOfType(System.Type, System.Boolean)
    UnityEngine.Object.DontDestroyOnLoad(UnityEngine.Object)
    UnityEngine.Object.DestroyObject(UnityEngine.Object, System.Single)
    UnityEngine.Object.DestroyObject(UnityEngine.Object)
    UnityEngine.Object.FindSceneObjectsOfType(System.Type)
    UnityEngine.Object.FindObjectsOfTypeIncludingAssets(System.Type)
    UnityEngine.Object.FindObjectsOfType<T>()
    UnityEngine.Object.FindObjectsOfType<T>(System.Boolean)
    UnityEngine.Object.FindObjectOfType<T>()
    UnityEngine.Object.FindObjectOfType<T>(System.Boolean)
    UnityEngine.Object.FindObjectsOfTypeAll(System.Type)
    UnityEngine.Object.FindObjectOfType(System.Type)
    UnityEngine.Object.FindObjectOfType(System.Type, System.Boolean)
    UnityEngine.Object.ToString()
    UnityEngine.Object.name
    UnityEngine.Object.hideFlags
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: UnityEngine.XR.ARFoundation
    Syntax
    [DisallowMultipleComponent]
    [DefaultExecutionOrder(-2147483648)]
    public sealed class ARSession : SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor, XRSessionSubsystem.Provider>

    Properties

    attemptUpdate

    If the device supports XR but does not have the necessary software, some platforms allow prompting the user to install or update the software. If attemptUpdate is true, a software update will be attempted. If the appropriate software is not installed or out of date, and attemptUpdate is false, then AR will not be available.

    Declaration
    public bool attemptUpdate { get; set; }
    Property Value
    Type Description
    Boolean

    currentTrackingMode

    Get the current TrackingMode in use by the session.

    Declaration
    public TrackingMode currentTrackingMode { get; }
    Property Value
    Type Description
    TrackingMode

    frameRate

    Get the number of AR frames produced per second, or null if the frame rate cannot be determined.

    Declaration
    public int? frameRate { get; }
    Property Value
    Type Description
    Nullable<Int32>

    matchFrameRate

    If true, the session will block execution until a new AR frame is available. This property is obsolete. Use matchFrameRateRequested or matchFrameRateEnabled instead.

    Declaration
    [Obsolete("Use matchFrameRateRequested or matchFrameRateEnabled instead. (2020-01-28)")]
    public bool matchFrameRate { get; set; }
    Property Value
    Type Description
    Boolean

    matchFrameRateEnabled

    If true, the underlying subsystem will attempt to synchronize the AR frame rate with Unity's.

    Declaration
    public bool matchFrameRateEnabled { get; }
    Property Value
    Type Description
    Boolean
    See Also
    matchFrameRateRequested

    matchFrameRateRequested

    If true, the session will block execution until a new AR frame is available and set Application.targetFrameRate to match the native update frequency of the AR session. Otherwise, the AR session is updated independently of the Unity frame.

    Declaration
    public bool matchFrameRateRequested { get; set; }
    Property Value
    Type Description
    Boolean
    Remarks

    If enabled with a simple scene, the ARSession.Update might appear to take a long time. This is because your application is waiting for the next AR frame, similar to the way Unity will WaitForTargetFPS at the end of a frame. If the rest of the Unity frame takes non-trivial time, then the next ARSession.Update will take a proportionally smaller amount of time.

    This option does three things:

    • Enables a setting on the XRSessionSubsystem which causes the update to block until the next AR frame is ready.
    • Sets Application.targetFrameRate to the session's preferred update rate.
    • Sets QualitySettings.vSyncCount to zero.

    These settings are not reverted when the AR Session is disabled.

    notTrackingReason

    The reason AR tracking was lost.

    Declaration
    public static NotTrackingReason notTrackingReason { get; }
    Property Value
    Type Description
    NotTrackingReason

    requestedTrackingMode

    Get or set the TrackingMode for the session.

    Declaration
    public TrackingMode requestedTrackingMode { get; set; }
    Property Value
    Type Description
    TrackingMode

    state

    The state of the entire system. Use this to determine the status of AR availability and installation.

    Declaration
    public static ARSessionState state { get; }
    Property Value
    Type Description
    ARSessionState

    Methods

    CheckAvailability()

    Start checking the availability of XR on the current device.

    Declaration
    public static IEnumerator CheckAvailability()
    Returns
    Type Description
    IEnumerator

    An IEnumerator used for a coroutine.

    Remarks

    The availability check can be asynchronous, so this is implemented as a coroutine. It is safe to call this multiple times; if called a second time while an availability check is being made, it returns a new coroutine which waits on the first.

    Install()

    Begin installing AR software on the current device (if supported).

    Declaration
    public static IEnumerator Install()
    Returns
    Type Description
    IEnumerator

    An IEnumerator used for a coroutine.

    Remarks

    Installation can be asynchronous, so this is implemented as a coroutine. It is safe to call this multiple times, but you must first call CheckAvailability().

    You must call CheckAvailability() before trying to start the installation, and the state must not be Unsupported or this method will throw InvalidOperationException.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if state is None or Unsupported.

    OnDestroy()

    Invoked when this MonoBehaviour is destroyed. Affects the state.

    Declaration
    protected override void OnDestroy()
    Overrides
    UnityEngine.XR.ARFoundation.SubsystemLifecycleManager<UnityEngine.XR.ARSubsystems.XRSessionSubsystem, UnityEngine.XR.ARSubsystems.XRSessionSubsystemDescriptor, UnityEngine.XR.ARSubsystems.XRSessionSubsystem.Provider>.OnDestroy()

    OnDisable()

    Invoked when this MonoBehaviour is disabled. Affects the state.

    Declaration
    protected override void OnDisable()
    Overrides
    UnityEngine.XR.ARFoundation.SubsystemLifecycleManager<UnityEngine.XR.ARSubsystems.XRSessionSubsystem, UnityEngine.XR.ARSubsystems.XRSessionSubsystemDescriptor, UnityEngine.XR.ARSubsystems.XRSessionSubsystem.Provider>.OnDisable()

    OnEnable()

    Creates and initializes the session subsystem. Begins checking for availability.

    Declaration
    protected override void OnEnable()
    Overrides
    UnityEngine.XR.ARFoundation.SubsystemLifecycleManager<UnityEngine.XR.ARSubsystems.XRSessionSubsystem, UnityEngine.XR.ARSubsystems.XRSessionSubsystemDescriptor, UnityEngine.XR.ARSubsystems.XRSessionSubsystem.Provider>.OnEnable()

    Reset()

    Resets the AR Session.

    Declaration
    public void Reset()
    Remarks

    Resetting the session destroys all trackables and resets device tracking (for example, the position of the session is reset to the origin).

    Events

    stateChanged

    This event is invoked whenever the state changes.

    Declaration
    public static event Action<ARSessionStateChangedEventArgs> stateChanged
    Event Type
    Type Description
    Action<ARSessionStateChangedEventArgs>
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023