EasyAR project AR Foundation scene configuration and usage
In Unity, using AR Foundation often relies on EasyAR to address the device limitations of AR Foundation. The following content explains how to correctly configure and use AR Foundation in an EasyAR scene, as well as how to dynamically enable AR Foundation based on device support.
Before you begin
- Read EasyAR support for Unity XR framework to understand EasyAR's support for the Unity XR framework and when you might consider using AR Foundation.
- Read Enable AR Foundation in EasyAR projects to learn how to install and configure AR Foundation in EasyAR projects.
Add AR Foundation components
Add AR Session and XR Origin from AR Foundation to the EasyAR scene.
Add AR Session
Right-click on a blank area in the Hierarchy view, and add Unity's ARSession to the scene through the menu XR > AR Session.

Note
This AR Session is different from EasyAR's AR Session, and they need to coexist in the scene.
Add XR Origin
Right-click on a blank area in the Hierarchy view, and add Unity's XROrigin to the scene via the menu XR > XR Origin (Mobile AR).

Note
This XR Origin overlaps with the functionality of EasyAR's XR Origin. You need to use Unity's XR Origin instead of EasyAR's XR Origin.
If there was an EasyAR XR Origin in the scene previously, usually named XR Origin (EasyAR), you need to move its child objects under the newly created XR Origin, then delete the XR Origin (EasyAR).

At this point, if the newly created XR Origin does not have an XR Origin Child, you need to add it manually.
In the Hierarchy view, select XR Origin and right-click, then add an XR Origin Child under the XR Origin via the menu EasyAR Sense > Origin > Origin : XR Origin Child.

Configure camera
If there was a Camera for AR in the scene before, you will find an extra main camera appearing in the scene. You need to delete the original camera.

Then select the Main Camera under XR Origin and configure the camera according to the instructions in Camera configs.
Finally, a complete EasyAR scene with AR Foundation added should look something like this:
Caution
If you need to modify the AR Foundation configuration through ARCameraManager.currentConfiguration, note that some phones (such as Xiaomi 10) have issues where they cannot retrieve images after modifying the configuration, making EasyAR unusable (the app has an image background but EasyAR functions do not respond). Therefore, it is generally not recommended to modify the configuration. If modification is necessary, ensure there is a fallback plan for when EasyAR becomes unusable.
Device compatibility and dynamically enabling AR Foundation
EasyAR is compatible with many more devices than AR Foundation, so configuration is required to ensure that the application only enables AR Foundation when needed and completely disables it in all other cases.
Check frame source component
Generally, sessions created through the EasyAR menu will automatically add ARCoreARFoundationFrameSource and ARKitARFoundationFrameSource (except for some image tracking that does not require SLAM functionality).

Important
ARCoreARFoundationFrameSource and ARKitARFoundationFrameSource are frame sources provided by EasyAR to enable AR Foundation functionality on devices that support AR Foundation. If the session in the scene does not contain these frame sources, AR Foundation functionality cannot be enabled.
If the session in the scene does not contain these frame sources, you can manually add them through the menu.

To run on phones that do not support AR Foundation, you also need to ensure that the session contains frame sources other than AR Foundation. A typical ARSession should look like the following,

Tip
You can sort the frame sources according to actual needs. During runtime, the session will select the first available frame source in the transform order based on device support.
Enable AR Foundation only when needed
Since the underlying implementation of AR Foundation on mobile devices is ARCore and ARKit, it can only be used on limited devices, especially on many domestic Android phones where it is not available. Therefore, it is generally recommended to enable AR Foundation and related functional scripts only on supported devices.
EasyAR can automatically handle these operations. This feature can be enabled or disabled through the Unity XR > Unity XR Auto Switch option in Project Settings > EasyAR > Sense. For detailed instructions, please refer to Auto-switching Unity XR objects.
Scenes that maintain AR Foundation compatibility
Scenes with properly added AR Foundation components can function correctly whether the AR Foundation package is installed or not.
When AR Foundation is not installed, its features and corresponding frame sources will be unavailable, and some scripts in the scene will be missing, which is normal.


Tip
Many samples can work correctly whether the AR Foundation package is installed or not. To enable AR Foundation support in these samples, simply enable AR Foundation in the EasyAR project.
Next steps
Related topics
- Related AR components mentioned in the text:
- AR Foundation provides motion tracking capabilities on some devices. For the relationship between motion tracking and various EasyAR features, you can refer to the following content:
- For more information about AR Foundation scene configuration, you can read the official AR Foundation documentation. Please select the corresponding document version before reading: