Table of Contents

Center mode of AR session

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

Before you begin

  • Learn the basic concepts, components, and workflow of a session through Introduction to AR Session.
  • Understand the role of the camera in an AR scene and how the session controls the camera properties to ensure a proper AR experience through Camera.
  • Learn the basic concepts, components, and lifecycle of XR Origin through XR Origin.
  • Understand the basic concepts, states, and lifecycle of a target 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 also 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. This reference point is represented in the Unity scene as the center object (CenterObject). The center mode (CenterMode) is the rule that determines which object the center object is during the session's operation.

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

  • A tracked target
  • XR Origin
  • Camera

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

In Unity, the session supports the following four center modes:

Name Diagram Description
FirstTarget

SpecificTarget
alt text Uses the target as the center, which can move freely. Among them,
  • FirstTarget uses the first tracked target as the center.
  • SpecificTarget uses the specified target as the center.
The camera and XR Origin in the session, as well as other targets, are controlled by the session and move relative to the center target.
SessionOrigin alt text Uses the 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: the blue sphere represents the XR Origin, the blue cone represents the camera, and the yellow image represents the target. In different center modes, the session selects different objects as the center object, and the diagram displays the local coordinate system of the corresponding object.

Tip

If you have experience using AR Foundation, you may notice that AR Foundation does not have a similar concept. In fact, the behavior mode of AR Foundation 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 by the current session or a third-party framework (such as AR Foundation). The existence of center modes ensures that the session can correctly control the motion behavior of objects in the scene under different operating environments.

For example, if AR Foundation or a Unity XR headset SDK controls the relative motion relationship between XR Origin and camera, XR Origin, as a design of the Unity XR framework, can be moved by the session, while camera cannot. In this case, the session will restrict the center mode to FirstTarget, SpecificTarget, or SessionOrigin, so that for the session, the center will be XR Origin or a certain target, while for the Unity XR framework, the center will still be XR Origin, and the entire system can work perfectly.

Warning

In Unity AR, any object that exists in the Unity world coordinate system and does not adjust its transform according to the session component may not be displayed correctly. Because the session adjusts the position and orientation of other objects in the scene based on the position and orientation of the center object, if an object is not controlled by the session, its position and orientation may not match the position and orientation calculated by the session, leading to unexpected behavior.

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

The correct approach is to always place the content to be displayed under a target node or under the XR Origin node (if the content needs to move with the XR Origin). This way, the position and orientation of the content will be adjusted according to the session's calculations, ensuring that the content can be correctly overlaid in the real world.

Manually aligning the position and orientation of the content with target or XR Origin is acceptable, but it must be done at the correct time. For reference, see Choosing the appropriate center mode.

Valid center modes

Not all center modes are valid in every situation. The session determines which center modes are valid based on the current runtime environment and the selected frame source, ensuring correct control over the movement behavior of objects in the scene. The ARSession.AvailableCenterMode property can be used to retrieve 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 and the frame source used during recording has no motion data
  • ExternalImageStreamFrameSource
Yes No -
  • FirstTarget
  • SpecificTarget
  • Camera
  • ARCoreFrameSource
  • AREngineFrameSource
  • ARKitFrameSource
  • InertialCameraDeviceFrameSource
  • MotionTrackerFrameSource
  • ThreeDofCameraDeviceFrameSource
  • FramePlayer and the frame source used during recording has motion data
Yes Yes Yes
  • FirstTarget
  • SpecificTarget
  • SessionOrigin
  • Camera (*)
* Only valid when camera is not
a child node of XR Origin
  • ARCoreARFoundationFrameSource
  • ARKitARFoundationFrameSource
  • VisionOSARKitFrameSource
  • XREALFrameSource
  • ExternalDeviceFrameSource and OriginType is XROrigin or Custom
    • PicoFrameSource
    • RokidFrameSource and not using UXR
No Yes Yes
  • FirstTarget
  • SpecificTarget
  • SessionOrigin
  • ExternalDeviceFrameSource and OriginType is None
    • RokidFrameSource and using UXR
No Yes No
  • SessionOrigin

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

Characteristics of different center modes

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

The video content is as follows:

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

  • One is a Christmas tree, which remains stationary. It is tracked using the sparse spatial map feature.
  • The other is an A4 sheet of paper with a pre-printed image, which can be moved. It is tracked using the image tracking feature.

When recording the video, the observer (the 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 have added some markers to different objects in the scene:

  • Christmas tree: When being tracked, bright blue point clouds are overlaid on the space it occupies. These markers disappear when tracking is lost.
  • A4 sheet of paper: When being tracked, a panda is overlaid directly above it. An additional image identical in content and size to the A4 paper is displayed in the Game view. 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 principal axis of the cone aligned with the camera's line of sight.

These videos were recorded in the Unity editor's Play mode using simulated runtime data. The left side of the video 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 the phone.

FirstTarget and SpecificTarget center mode

Firsttarget and specifictarget center mode is a mode that uses a certain target as the central object. In these two modes, besides the central target, the camera and XR Origin in the session, as well as other targets, are controlled by the session and move relative to the central target.

Some targets can move in the real world, such as the A4 paper in the video.

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

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

In the video above, the central object is a christmas tree tracked via sparse spatial mapping. It can be observed that without external intervention, 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 does not move, but this is because it remains stationary relative to the christmas tree.

In these two modes, the central target serving as the reference point can move freely. In such cases, the camera and XR Origin, as well as other targets in the session, will all move accordingly, and their transforms cannot be externally controlled.

In the video above, the central object is an A4 paper tracked via image tracking. It can be observed that when we manually move the A4 paper (panda), the camera (blue cone), XR Origin (blue sphere), and christmas tree (bright blue point cloud) all move accordingly. Note that the content displayed in the Game view does not change at this time because the position and orientation of the camera relative to the A4 paper and other objects remain unchanged.

The difference between firsttarget and specifictarget mode lies in how the central target might change during runtime, but the method of selecting the center differs when such changes occur. To explain this, we need to consider the processes of successful tracking and loss.

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

FirstTarget center mode center change

In FirstTarget center mode, the session always centers around the first tracked target. If this target is lost, the session will reselect the center. When the session tracks or newly tracks another target, that target will be chosen as the new center object.

Reselection of the center occurs in the following scenarios:

  • No target is in a tracked state in the current frame
    If the SessionOrigin mode is active, the session will fall back to SessionOrigin mode, selecting the XR Origin as the center object; otherwise, the session will fall back to Camera mode, selecting the camera as the center object.

  • There are targets in a tracked state in the current frame, and no target was in a tracked state in the previous frame
    The session will select one of the tracked targets as the center object.

  • There are targets in a tracked state in the current frame, and the previous center target is lost in the current frame
    The session will select 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. It can be observed that when the A4 paper (panda) is lost, the session reselects the center object, and the Christmas tree (bright blue point cloud) becomes the new center object. At the end of the video, the A4 paper is tracked again, but it does not become the center object because the Christmas tree is already the center object.

SpecificTarget center mode center changes

In SpecificTarget center mode, the session always centers around the specified target. If this target is lost in tracking, the session will reselect the center, but it will not choose another target as the new center object. When the session regains tracking of the specified target, it will still be selected as the center object.

Reselection of the center occurs in the following scenarios:

  • The specified target is not tracked in the current frame
    In this case, if the SessionOrigin mode is valid, the session will fall back to SessionOrigin mode and select XR Origin as the center object; otherwise, the session will fall back to Camera mode and select camera as the center object.

  • The specified target is in a tracked state in the current frame, and the specified target was not tracked in the previous frame
    In this case, the session will select the specified target as the center object.

In the video above, the center object is specified as an A4 paper tracked via image tracking. It can be observed that when the A4 paper (panda) is lost in tracking, the session does not select another target as the new center object, and the Christmas tree (bright blue point cloud) does not become the center object. At the end of the video, the A4 paper is tracked again, and it resumes as the center object.

SessionOrigin center mode

The SessionOrigin center mode is a mode that uses XR Origin as the central object. In this mode, the camera and target in the session are controlled by the session and move relative to the central XR Origin.

In the video above, the central object is the XR Origin. It can be seen that since there is no external operation, the XR Origin (blue sphere) remains stationary, while the camera (blue cone) and the A4 paper (panda) are moving. The Christmas tree (bright blue point cloud) is also not moving, but this is because it is stationary relative to the XR Origin.

In this mode, the central XR Origin as the reference point can move freely, and the camera and target in the session will follow. Their transforms cannot be controlled externally.

In the video above, the central object is the XR Origin. It can be seen that since we manually moved the XR Origin (blue sphere), the camera (blue cone), Christmas tree (bright blue point cloud), and A4 paper (panda) all moved accordingly. Note that the content displayed in the Game view does not change because the position and orientation of the camera relative to the XR Origin and other objects remain unchanged.

In SessionOrigin mode, the XR Origin must be valid, so the central object will not change in this mode.

Center camera mode

The center camera mode is a mode where the camera serves as the central object. In this mode, both the XR Origin and the target in the session are controlled by the session and move relative to the central camera.

In the video above, the central object is the camera. It can be observed that since there is no external operation, the camera (blue cone) remains stationary, while the XR Origin (blue sphere), the Christmas tree (light blue point cloud), and the A4 paper (panda) are all moving.

In this mode, the central camera, which serves as the reference point, can move freely. At this time, the XR Origin and the target in the session will follow its movement, and their transforms cannot be controlled externally.

In the video above, the central object is the camera. It can be seen that since we manually moved the camera (blue cone), the XR Origin (blue sphere), the Christmas tree (light blue point cloud), and the A4 paper (panda) all followed its movement. Note that the content displayed in the Game view does not change because the position and orientation of the camera relative to the XR Origin and other objects remain unchanged.

In camera mode, the camera must be valid, so the central object will not change in this mode.

Next steps