Table of Contents

Center mode of AR session

Center mode is a core concept in Unity AR, which determines which object is selected as the reference point (center object) for all AR tracking during session operation, and which objects in the session can move freely. Through the following content, you will understand the basic concepts of center mode and its impact on the movement behavior of objects in the scene.

Before you begin

  • Understand the basic concepts, composition, and workflow of sessions through Introduction to AR Session.
  • Learn about the role of the camera in AR scenes and how the session controls camera properties to ensure a proper AR experience through Camera.
  • Understand the basic concepts, composition, and lifecycle of XR Origin through XR Origin.
  • Learn about the basic concepts, states, and lifecycle of targets through Target.

Center object and center mode

In a session, one or more different AR features may be running simultaneously. These AR features may track different objects and may simultaneously use motion tracking to track the device's own position and orientation.

To ensure that the movement behavior of objects in the scene meets expectations, the session needs to select a reference point as the center for all AR tracking. The representation of this reference point in the Unity scene is the center object (CenterObject). Center mode (CenterMode) is the rule that determines which object this center object should be during session operation.

The center of a session can be one of the following objects:

  • A tracked target
  • XR Origin
  • Camera

Center mode determines which object the session selects as the center object and whether this object can move freely. Objects other than this object (including non-center cameras, XR Origin, and targets) are controlled by the session and move relative to the center object.

In Unity, session supports the following four center modes:

Name Diagram Description
FirstTarget

SpecificTarget
alt text Uses target as the center, which can move freely. Among them,
  • FirstTarget uses the first tracked target as the center.
  • SpecificTarget uses a specified target as the center.
The camera, XR Origin, and other targets in the session are controlled by the session and move relative to the center target.
SessionOrigin alt text Uses XR Origin as the center, which can move freely.
The camera and targets in the session are controlled by the session and move relative to the center XR Origin.
Camera alt text Uses the camera as the center, which can move freely.
The XR Origin and targets in the session are controlled by the session and move relative to the center camera.

The diagram shows three objects: a blue sphere represents XR Origin, a blue cone represents the camera, and a yellow image represents target. Under different center modes, the session selects different objects as the center object, with the diagram displaying their local coordinate systems.

Tip

If you have experience using AR Foundation, you may notice that similar concepts do not exist in AR Foundation. In fact, AR Foundation's behavior pattern is consistent with the SessionOrigin center mode.

In the session, the relative motion relationship between target and camera is controlled by the current session. The relative motion relationship between XR Origin and camera is controlled either by the current session or by a third-party framework (e.g., AR Foundation). The existence of center modes ensures that the session can correctly control the motion behavior of objects in the scene under different runtime environments.

For example, if AR Foundation or a headset SDK based on Unity XR controls the relative motion between XR Origin and camera, XR Origin—as designed by the Unity XR framework—can be moved by the session, while camera cannot. In this case, the session restricts the center mode to FirstTarget, SpecificTarget, or SessionOrigin. Thus, for the session, the center is XR Origin or a certain target, while for the Unity XR framework, the center remains XR Origin, allowing the entire system to function perfectly.

Warning

In Unity AR, any object existing in the Unity world coordinate system that does not adjust its transform according to session components may not display correctly. Because the session adjusts the position and orientation of other objects in the scene based on the center object's position and orientation, if an object is not controlled by the session, its position and orientation may be inconsistent with those calculated by the session, leading to unexpected behavior.

For example, if a panda model is placed in the world coordinate system, its position and orientation may not correspond to any real-world object, appearing to float in the air or move erratically.

The correct approach is to always place content to be displayed under a target node or under the XR Origin node (if the content needs to follow XR Origin). This way, the content's position and orientation are adjusted based on the session's calculations, ensuring it correctly overlays the real world.

Manually aligning content with target or XR Origin position and orientation is possible but must be done at the correct time. Refer to Choosing the appropriate center mode.

Available center mode

Not all center modes are valid under all circumstances. The session determines which center modes are valid based on the current runtime environment and selected frame source, ensuring correct control of scene object motion behavior. The ARSession.AvailableCenterMode property can be used to obtain the list of valid center modes for the current session.

Depending on the selected frame source, the session's valid center modes vary as follows:

Frame source Camera controlled Has motion data Has origin design Valid center modes
  • CameraDeviceFrameSource
  • FramePlayer with recorded frame source lacking motion data
  • ExternalImageStreamFrameSource
Yes No -
  • FirstTarget
  • SpecificTarget
  • Camera
  • ARCoreFrameSource
  • AREngineFrameSource
  • ARKitFrameSource
  • InertialCameraDeviceFrameSource
  • MotionTrackerFrameSource
  • ThreeDofCameraDeviceFrameSource
  • FramePlayer with recorded frame source having motion data
Yes Yes Yes
  • FirstTarget
  • SpecificTarget
  • SessionOrigin
  • Camera (*)
* Valid only if camera is not
a child node of XR Origin
  • ARCoreARFoundationFrameSource
  • ARKitARFoundationFrameSource
  • VisionOSARKitFrameSource
  • XREALFrameSource
  • ExternalDeviceFrameSource with OriginType as XROrigin or Custom
    • PicoFrameSource
    • RokidFrameSource without UXR
No Yes Yes
  • FirstTarget
  • SpecificTarget
  • SessionOrigin
  • ExternalDeviceFrameSource with OriginType as None
    • RokidFrameSource using UXR
No Yes No
  • SessionOrigin

Except when using FramePlayer, valid center modes are determined during session assembly. When using FramePlayer, valid center modes are dynamically determined per frame during runtime based on whether the output data contains motion information.

Characteristics of different center modes

Next, we will demonstrate the movement behavior of objects in different center modes through a series of example videos.

Video content is as follows:

In the real world, there are two different types of trackable objects:

  • One is a Christmas tree, which is stationary. It is tracked through sparse spatial mapping.
  • The other is an A4 paper with a pre-printed image, which can be moved. It is tracked through image tracking.

When recording the video, the observer (phone) starts from the right rear of the Christmas tree and moves around it. The A4 paper swings left and right in front of the observer.

For easier observation, we added some markers to different objects in the scene:

  • Christmas tree: When tracked, bright blue point clouds are overlaid in its occupied space. These markers disappear when tracking is lost.
  • A4 paper: When tracked, a panda is overlaid directly above it. The Game view additionally displays an image identical in content and size to the A4 paper. These markers disappear when tracking is lost.
  • XR Origin: A blue sphere is placed at its position
  • Camera: A blue cone is placed at its position, with the main axis of the cone aligned with the camera's line of sight.

These videos were recorded using simulated runtime data in Unity Editor's Play mode. The left side shows the Scene view, and the right side shows the Game view. The content of the Game view is the same as what the user sees in the real world through their phone.

FirstTarget and SpecificTarget center modes

The FirstTarget and SpecificTarget center modes use a certain target as the central object. In these modes, except for the central target, the camera, XR Origin, and other targets in the session are controlled by the session and move relative to the central target.

Some targets are movable in the real world, such as the A4 paper in the video.

In the video above, the center object is the A4 paper tracked via image tracking. It can be observed that without external manipulation, the A4 paper (panda) remains stationary, while the camera (blue cone), XR Origin (blue sphere), and Christmas tree (bright blue point cloud) are all moving.

Some targets are stationary in the real world, such as the Christmas tree in the video.

In the video above, the center object is the Christmas tree tracked via sparse spatial map. It can be observed that without external manipulation, the Christmas tree (bright blue point cloud) remains stationary, while the camera (blue cone) and A4 paper (panda) are moving. The XR Origin (blue sphere) also remains stationary, but this is because it is fixed relative to the Christmas tree.

In these two modes, the central target serving as the reference point can move freely. When this happens, the camera, XR Origin, and other targets in the session will follow its movement, and their transforms cannot be externally controlled.

In the video above, the center object is the A4 paper tracked via image tracking. It can be observed that after manually moving the A4 paper (panda), the camera (blue cone), XR Origin (blue sphere), and Christmas tree (bright blue point cloud) all follow its movement. Note that the content displayed in the Game view remains unchanged because the camera's position and orientation relative to the A4 paper and other objects remain consistent.

The difference between FirstTarget and SpecificTarget modes lies in how the central target may change during runtime, specifically in how the center is selected when such changes occur. To explain this, we need to consider the processes of tracking success and loss.

When the session's center object changes, ARSession.CenterObject will always reflect the current center object, but ARSession.CenterMode will not change.

Center change in FirstTarget center mode

In FirstTarget center mode, the session always centers on the first tracked target. If this target is lost, the session re-selects a center. When the session tracks or newly tracks another target, that other target becomes the new center object.

Re-selection occurs in the following situations:

  • When no target is tracked in the current frame
    If SessionOrigin mode is valid, the session degrades to SessionOrigin mode, selecting XR Origin as the center object; otherwise, it degrades to Camera mode, selecting camera as the center object.

  • When targets are tracked in the current frame, and no target was tracked in the previous frame
    The session selects one of the tracked targets as the center object.

  • When targets are tracked in the current frame, and the previous center target is lost in the current frame
    The session selects one of the tracked targets as the new center object.

In the video above, the center object is initially an A4 paper tracked via image tracking. When the A4 paper (panda) is lost, the session re-selects the center. The Christmas tree (bright blue point cloud) becomes the new center object. At the end, the A4 paper is re-tracked but does not become the center, as the Christmas tree is already the center.

SpecificTarget center mode center changes

In SpecificTarget center mode, the session always centers on the specified target. If this target is lost, the session re-selects a center but will not choose other targets as the new center. When the specified target is re-tracked, it regains center status.

Re-selection occurs in the following situations:

  • When the specified target is not tracked in the current frame
    If SessionOrigin mode is valid, the session degrades to SessionOrigin mode, selecting XR Origin as the center object; otherwise, it degrades to Camera mode, selecting camera as the center object.

  • When the specified target is tracked in the current frame, and was not tracked in the previous frame
    The session selects the specified target as the center object.

In the video above, the center is specified as the A4 paper tracked via image tracking. When the A4 paper (panda) is lost, the session does not select another target as center. The Christmas tree (bright blue point cloud) does not become the center. When the A4 paper is re-tracked, it resumes as the center object.

SessionOrigin center mode

SessionOrigin center mode uses XR Origin as the center object. In this mode, the camera and targets in the session move relative to the central XR Origin, controlled by the session.

In the video above, the center is XR Origin. With no external manipulation, XR Origin (blue sphere) remains stationary, while the camera (blue cone) and A4 paper (panda) move. The Christmas tree (bright blue point cloud) also remains stationary as it is static relative to XR Origin.

In this mode, the central XR Origin reference point can be freely moved. The camera and targets follow this movement, and their transforms cannot be externally controlled.

In the video above, manually moving XR Origin (blue sphere) causes the camera (blue cone), Christmas tree (bright blue point cloud), and A4 paper (panda) to follow. Note that the Game view shows no change, as the camera’s position and orientation relative to XR Origin and other objects remain consistent.

In SessionOrigin mode, XR Origin must remain valid, so the center object does not change.

Camera center mode

Camera center mode uses camera as the center object. In this mode, XR Origin and targets move relative to the central camera, controlled by the session.

In the video above, the center is the camera. With no external manipulation, the camera (blue cone) remains stationary, while XR Origin (blue sphere), Christmas tree (bright blue point cloud), and A4 paper (panda) move.

In this mode, the central camera can be freely moved. The XR Origin and targets follow this movement, and their transforms cannot be externally controlled.

In the video above, manually moving the camera (blue cone) causes XR Origin (blue sphere), Christmas tree (bright blue point cloud), and A4 paper (panda) to follow. The Game view shows no change, as the camera’s position and orientation relative to other objects remain consistent.

In Camera mode, camera must remain valid, so the center object does not change.

Next steps