Table of Contents

Choose the right center mode

Choosing the right center mode is crucial for content creation. Through the following content, you will learn how to obtain and modify the center mode, as well as suggestions for selecting the appropriate center mode.

Before you begin

Get available center modes

During a session, only the center modes available for the current session will be displayed in the Center dropdown of the Inspector panel. If the session is not started, all center modes will be displayed.

alt text

This image shows the available center modes for a session when using the CameraDeviceFrameSource in the editor.

In scripts, you can obtain the list of available center modes for the current session after the session is successfully assembled through the ARSession.AvailableCenterMode property.

For example, the following code demonstrates how to check if a center mode is available in the current session:

if (Session.AvailableCenterMode.Contains(mode))
{
    // mode is available in the current session
}

Change center mode

Open the Inspector panel and select the desired center mode from the Center dropdown menu.

alt text

In scripts, you can modify the center mode through the ARSession.CenterMode property.

For example, the following code demonstrates how to cycle through available center modes:

while (true)
{
    Session.CenterMode = (ARSession.ARCenterMode)(((int)Session.CenterMode + 1) % Enum.GetValues(typeof(ARSession.ARCenterMode)).Length);
    if (Session.AvailableCenterMode.Contains(Session.CenterMode)) { break; }
}

The session checks whether the current center mode is valid every frame. If it is valid, the session will immediately attempt to use the new center mode.

In the video above, the session initially uses the FirstTarget mode, with the center object being the Christmas tree (bright blue point cloud). We then manually change the center mode to Camera mode, and the center object becomes the camera (blue cone). For a detailed description of the video content, refer to AR Session's center mode.

When the session updates, if the modified center mode is invalid in the current session, the CenterMode property will automatically be reset to the first available center mode (usually FirstTarget or SessionOrigin), and a warning message will be logged:

Center mode {Value} is unavailable in this session, reset to {NewValue}.

How to choose the center mode

Aligning with real-world objects is the core requirement of AR content creation, and the center mode determines which object the session uses as a reference point to calculate the position and orientation of other objects in the scene. Therefore, choosing the appropriate center mode is crucial for content creation.

General advice

In many cases, using FirstTarget or SpecificTarget mode, with target as the center for content creation, is more user-friendly. This ensures that the reference points placed under target remain stationary and are not unnecessarily affected by the movement of XR Origin or camera (e.g., affecting physics system calculations). However, this is not absolute. Specifically:

  • When unsure which mode to choose, use the default value, i.e., FirstTarget as the center
    Since most AR functionalities have inherent errors and continuously correct these errors during operation, this can cause seemingly stationary objects in the real world (e.g., sparse spatial map target and motion-tracked XR Origin) to have relative movement in the virtual space. In such cases, using target as the center is more aligned with content creation needs compared to using XR Origin.

  • When multiple targets are tracked simultaneously
    For scenarios where multiple targets are tracked simultaneously, even if the objects in the real world are relatively stationary, these targets may still exhibit relative movement due to computational errors. The choice of the central object should be based on actual needs, and typically, the FirstTarget mode is a more suitable choice.

  • When to use SessionOrigin mode
    SessionOrigin is suitable for scenarios where only motion tracking is active, making XR Origin the sole reference point. It is also applicable in special cases, such as when the headset manufacturer does not correctly implement the reference point for motion tracking, necessitating the use of Unity's world center and forcing the use of SessionOrigin mode.

  • Usage scenarios for Camera mode
    Camera mode is more suitable for scenarios where the physical camera is stationary (e.g., card battle AR using a fixed camera). In such cases, using Camera mode is more convenient for content creation.

Common center modes for different AR features

When using certain AR features individually, some center modes are more commonly used. The table below lists the commonly used center modes corresponding to these AR features:

Feature Common center modes
Mega FirstTarget or SpecificTarget
Motion tracking SessionOrigin
Plane detection SessionOrigin
Sparse spatial map FirstTarget or SpecificTarget
Dense spatial map SessionOrigin
Surface tracking FirstTarget or SpecificTarget
Image tracking FirstTarget, SpecificTarget, or Camera
Image cloud recognition FirstTarget, SpecificTarget, or Camera
Object tracking FirstTarget, SpecificTarget, or Camera

Considerations for cross-device development

When developing AR applications for cross-device compatibility, it's essential to consider the support for different center modes across devices.

  • If the scope is limited to phones and tablets, there are usually no significant issues. However, if you plan to use SessionOrigin, ensure that motion tracking is functional.
  • Extra caution is required when working with headsets:
    • Refer to available center modes to determine which center modes are supported by the target devices. If using third-party extensions, check the OriginType they employ.
    • When using Rokid devices, avoid UXR whenever possible. XRI ensures compatibility with most center modes.
    • On headsets that do not support FirstTarget and SpecificTarget modes, note that features like Mega or image tracking will struggle to remain stationary relative to the Unity world coordinate system.

Content that can be correctly displayed in every center mode

Warning

In Unity AR, any object that exists in the Unity world coordinate system and whose transform is not adjusted according to the session component may not be displayed correctly.

If some models are placed in the world coordinate system, their positions and orientations may not correspond to any object in the real world. The actual runtime effect may coincidentally work, or it may appear to float in the air or move around randomly.

To ensure content is correctly displayed in any center mode, the correct approach is:

  • Always place the content to be displayed under the corresponding target node, or under the XR Origin node (if the content needs to follow the XR Origin's movement)
  • Or manually align the content's position and orientation with target or XR Origin, but this must be done after the ARSession.PostSessionUpdate event
Note

This does not guarantee that all content elements will work correctly, as some Unity features only work in the world coordinate system (e.g., the physics system). Choosing the appropriate center mode remains important.