Unity AR tracking target - target
Target in Unity represents various trackable objects. Through the following content, you will learn the basic concepts, states, and lifecycle of the tracking target in Unity AR.
Before you begin
- Learn the basic concepts, components, and workflow of a session through Introduction to ARSession.
What is target
Target refers to the representation in Unity of objects that are recognized and tracked by AR features. In the real world, these objects can be images, 3D objects, spatial maps, etc. By recognizing and tracking these objects, AR applications can overlay virtual content in the real world, enabling rich interactive experiences.
Some targets are stationary in the real world (such as posters on a wall).
This video demonstrates a simple AR scene with image tracking. On the left is the
Hierarchyview, in the middle is theSceneview, and on the right is theGameview. The video was recorded in the Unity editor'sPlaymode using simulated runtime data. The content in theGameview is the same as what users would see in the real world on their mobile devices. In this video, the target (ImageTarget) represents a business card in the real world. We placed a yellow sphere above it to observe its movement.It can be seen that the target is fixed in both the real world and the scene, while the camera representing the user (blue cone) moves according to the user's movement in the real world. The white cone captures the trajectory of the camera's position and orientation over a period of time. The yellow sphere is under the target (ImageTarget) node, which is a typical organizational structure for objects in such scenes.
Some targets are movable in the real world (such as posters on a bus).
This video shows the same scene, but this time we moved the target (business card) in the real world. It can be seen that after the target moves, the yellow sphere follows the business card, and the sphere in the
Gameview remains aligned with the business card.
For clarity, the gizmo display of ImageTarget was turned off in the above two videos, and both used the SessionOrigin center mode. In these two videos, the movement of objects in the Scene view is the same as in the real world. In actual AR scenes, this movement relationship is more complex.
Behavior of target in different center modes
In Unity, the central reference point for all AR tracking is called the session center, and the rule that determines this center during the session is called the center mode. The behavior of the target varies in different center modes:
In the SessionOrigin center mode, the target cannot be moved freely.
The SessionOrigin mode can only exist in scenarios with motion tracking.
Although this mode works well in simple scenarios to demonstrate the movement of the target and the camera in the real world, it is not commonly used in actual AR scenarios because, in this mode, the session controls the movement of the target. Due to calculation errors in motion tracking or the AR function itself, it is difficult to ensure that the target remains completely fixed. In this case, the content root node must follow the movement of the target, which can affect content behavior (such as the physics system) in the Unity system.
In the FirstTarget or SpecificTarget center mode, if the target is the object selected as the center, it can be moved freely.
Generally, the FirstTarget mode is more commonly used. It ensures that the first tracked object in the scene is not controlled by the session. If there is no need to move the target, it remains fixed, regardless of whether the corresponding object in the real world is moving.
In the FirstTarget or SpecificTarget center mode, if the target is not the object selected as the center, and in the Camera center mode, the target cannot be moved freely.
Generally, when tracking multiple objects simultaneously, even if these objects are relatively fixed in the real environment, due to calculation errors, only one target can be uncontrolled by the session at any given time. Depending on the configuration, the movement of other targets is not guaranteed—even if there is no movement in reality, there may be slight movement in the scene. The behavior of multiple objects being tracked simultaneously should be fully considered, and content strategies should be adjusted accordingly.
For details about center modes and the movement of objects in the scene, refer to: Center mode.
Status of the target
The status of the target reflects its recognition and tracking status in the current session. Common states include:
- Tracked: The target has been successfully identified and tracked, allowing the AR application to overlay virtual content on it, which will align with the real-world object.
- Not tracked: The target is currently not recognized or tracked. If the AR application still overlays virtual content on it, the content will not align with the real-world object.
Additionally, the following events can be triggered when the status changes:
- TargetFound: Triggered when the target is successfully identified and tracked.
- TargetLost: Triggered when the target loses its tracked status.
Lifecycle of the target
In Unity AR scenes, the target is typically managed by the corresponding frame filter component. The frame filter processes image data from the frame source and identifies and tracks the target within it. The lifecycle of the frame filter depends on the session. Although different AR implementations may vary, in most cases, the target is loaded when the session starts and remains under the control of the session after loading. When the session stops, the target is unloaded and remains in place until it is used by the next session or manually deleted.
Next steps
- Try getting target state
- Try using the corresponding target in various AR features