AR Foundation Scene Build

Suggest to read AR Foundation Configuration first to setup AR Foundation correctly, and make sure Unity XR > AR Foundation Support of EasyAR Settings is on.

When to Use AR Foundation

Unity AR Foundation provides a wrapper for some cross-platform motion tracking capabilities. Please read Motion Tracking and EasyAR Features to understand the relationship between EasyAR features and motion tracking, and determine whether and when to use AR Foundation.

In most cases, you can work without AR Foundation, and EasyAR will function properly on all supported devices. You should consider using AR Foundation in the following two scenarios:

  1. If you need to use ARCore on all Xiaomi and Redmi phones that support ARCore, use AR Foundation. Due to bugs in Xiaomi’s implementation, EasyAR’s ARCore implementation has disabled some Xiaomi phones, including the Mi 9, Mi 10, Redmi K20, Redmi K30, Redmi K40 series, etc. (this list is not exhaustive and may be adjusted as needed). On these phones, ARCore will not be used by default, and EasyAR motion tracking will be used on phones that support EasyAR motion tracking.

  2. If you need to use certain features provided by ARCore or ARKit that are not wrapped in EasyAR, you can also use AR Foundation. For example, AR Foundation provides support for ARKit’s ARKitFaceManager, which is not wrapped in EasyAR.

However, using AR Foundation may not always be optimal for EasyAR’s features:

  1. When using EasyAR Mega, the default configuration of AR Foundation is not optimal. Although EasyAR provides options for optimization, note that some phones (e.g., Xiaomi Mi 10) have bugs that prevent image acquisition after modifying the configuration, rendering EasyAR unusable. Use with caution.

  2. On some Xiaomi phones disabled by EasyAR, the input data to EasyAR is grayscale rather than color, which may affect the performance of certain algorithms.

Attention

AR Foundation support is implemented as EasyAR Sense custom camera. EasyAR Sense will stop responding after a fixed and limited time per run if trial product (personal license, trial XR license, or trial Mega services, etc.) is being used with custom camera or HMD. There is no limitation when using a paid license for EasyAR Sense and paid EasyAR Mega service.

Add EasyAR Support in AR Foundation Scene

There is not much special about adding EasyAR in an AR Foundation scene; you can refer to AR Session, Camera, and XR Origin for creation and configuration.

Note that the XR Origin and Camera should use existing objects in the scene; you do not need to create them separately.

Add AR Foundation Support in EasyAR Scene

Remove Camera and XR Origin (EasyAR)

  1. If your scene already contains a Camera, delete it.

../_images/image_as4_1.png
  1. If your scene already contains XR Origin (EasyAR), delete it.

../_images/image_as4_2.png

Move all child objects under this node to the newly created XR Origin node below. If not moved, these child objects will not work as expected.

Adding Unity AR Session and XR Origin

Follow the AR Foundation Introduction under Project Setup > Scene Setup to add AR Foundation components. Be sure to select the version of AR Foundation you are using. You need to add at least AR Session and XR Origin to the scene.

Use the context menu XR > AR Session to add Unity’s ARSession to the scene (this is different from EasyAR’s ARSession and does not conflict).

../_images/image_as4_3.png

Use the context menu XR > XR Origin (Mobile AR) to add Unity’s XR Origin to the scene (similar to EasyAR’s XR Origin, you need to delete EasyAR’s XR Origin).

../_images/image_as4_4.png

Reference Camera to adjust Camera parameters.

Device compatibility and enabling of AR Foundation in runtime

EasyAR supports many more devices than AR Foundation. Unless you only need to run on phones that support AR Foundation, you should configure your project to enable AR Foundation only when necessary and keep it completely disabled otherwise.

Ensure that EasyAR’s ARSession contains the FrameSource you need

Refer to AR Session. An ARSession created via the feature menu will usually automatically include ARCore ARFoundation and ARKit ARFoundation (excluding some cases like image tracking that do not require SLAM).

../_images/image_as4_5.png

If they are not in your ARSession, you can manually add them through the menu.

../_images/image_as4_6.png

To run on phones that do not support AR Foundation, ensure the ARSession also contains Frame Sources other than AR Foundation. A typical ARSession (the default configuration created via the menu) might look like this,

../_images/image_as4_7.png

Enable AR Foundation only on supported devices

Because Unity’s AR Foundation 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.

The plugin has this feature built in; make sure EasyAR Settings’s Unity XR > Unity XR Auto Switch is enabled. You can read Unity XR Auto Switch to understand its behavior, or enable and disable the AR Foundation scripts as needed.

Retaining AR Foundation compatibility in EasyAR scenes

A scene that correctly adds AR Foundation components can work normally whether the AR Foundation package is installed or not.

When AR Foundation is not installed, AR Foundation features and their corresponding Frame Sources will be unavailable, and some scripts in the scene will be missing; this is normal.

../_images/image_as4_8.png ../_images/image_as4_9.png

Many samples in the plugin are configured this way. If you need to enable AR Foundation support in these samples, simply configure AR Foundation correctly following AR Foundation Configuration.