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 talk to the same session and will conflict with each other.
Enabling or disabling the ARSession will start or stop the session, respectively.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.ARFoundation
Syntax
[DisallowMultipleComponent]
[DefaultExecutionOrder(-2147483648)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@3.0/api/UnityEngine.XR.ARFoundation.ARSession.html")]
public sealed class ARSession : SubsystemLifecycleManager<XRSessionSubsystem, XRSessionSubsystemDescriptor>
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 |
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
and set
Application.targetFrameRate
to match the native update frequency of the AR session.
Otherwise, the AR session is updated indpendently of the Unity frame.
Declaration
public bool matchFrameRate { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
If enabled with a simple scene, the ARSession.Update
may appear to take a long time.
This is simply 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 less 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
notTrackingReason
The reason AR tracking was lost.
Declaration
public static NotTrackingReason notTrackingReason { get; }
Property Value
Type | Description |
---|---|
NotTrackingReason |
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 |
Remarks
The availability check may 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 |
Remarks
Installation may 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 tring to Install
and the
OnDestroy()
Declaration
protected override void OnDestroy()
Overrides
OnDisable()
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Creates and initializes the session subsystem. Begins checking for availability.
Declaration
protected override void OnEnable()
Overrides
Reset()
Resets the AR Session. This destroys the current session, including all trackables, and then establishes a new session.
Declaration
public void Reset()
Events
stateChanged
This event is invoked whenever the
Declaration
public static event Action<ARSessionStateChangedEventArgs> stateChanged
Event Type
Type | Description |
---|---|
Action<ARSessionStateChangedEventArgs> |