Unity XR Auto Switch¶
Automatically switch Unity XR (for example AR Foundation) objects. Mainly designed for mobile AR; under default configuration the feature will be disabled on headsets. Global configuration switch: EasyAR Settings , Unity XR > Unity XR Auto Switch .
Because Unity’s AR Foundation on mobile is implemented on mobile using ARCore and ARKit, it can only be used on a limited set of devices, and especially many Android phones on some markets may not work. Therefore it is generally recommended to enable the corresponding scripts only on supported devices. If you need to automatically switch AR Foundation at runtime, you need to create AR Foundation’s ARSession and XR Origin in the scene via Unity’s right-click menu, and use AR Foundation’s camera.
Unity XR > Unity XR Auto Switch has detailed controls. When all control switches are enabled,
In the editor, ARSession will disable AR Foundation’s ARSession.
At runtime, ARSession will disable all Unity XR Core components and AR Foundation components in Awake.
At runtime, if the selected frame source inherits from ARFoundationFrameSource or is an ExternalDeviceFrameSource that implements the XROrigin origin, the previously disabled Unity XR Core and AR Foundation components will be re-enabled in ARSession.StartSession (components that were not disabled by EasyAR will not be enabled). If another frame source is selected, all Unity XR Core and AR Foundation components will be disabled in ARSession.StartSession.
At runtime, all Unity XR Core components and AR Foundation components will be disabled in ARSession.StopSession.
Default configuration enablement conditions:
Enabled on Windows and macOS.
When the switcher starts, it is enabled if the mobile AR (ARKit/ARCore) loader is active.
When the switcher starts, if there are loaders other than mobile AR (ARKit/ARCore) but none of the loaders are active, it is disabled.
Note
Note that XR Interaction Toolkit components are not controlled by this feature, and their availability within EasyAR is unverified. In theory, functions that only use the XROrigin GameObject and its Camera should work, but you may need to set ARSession.ARCenterMode to SessionOrigin . If the feature does not work correctly, you need to manage XR Interaction Toolkit components yourself and disable related components when the frame source does not inherit from ARFoundationFrameSource.
Custom behavior handling¶
If you need to control the switching of these components yourself, or if EasyAR’s behavior interferes with the normal operation of certain components, make sure to turn off these options.
You can also implement similar functionality manually. You can enable or disable EasyAR Settings , Unity XR > Unity XR Auto Switch option as needed, and modify according to the following basic rules:
Disable AR Foundation’s ARSession in the editor (Unity ARSession excutes earlier than any other scripts).
Disable all Unity XR Core components, AR Foundation components, and related components or features you need to control before AR Foundation starts working.
If EasyAR’s ARSession’s Assemble process selects ARCoreARFoundationFrameSource or ARKitARFoundationFrameSource, enable all previously disabled components or features.
If EasyAR’s ARSession’s Assemble process selects another FrameSource, leave it unchanged.