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 tracking target in Unity AR.
Before you start
- Understand the basic concepts, composition, and workflow of session through Introduction to ARSession.
What is target
Target refers to the representation in Unity of objects recognized and tracked by AR capabilities. These objects in the real world can be images, 3D objects, spatial maps, etc. By recognizing and tracking these objects, AR applications can overlay virtual content onto the real world, enabling rich interactive experiences.
Some targets are stationary in the real world (such as posters on walls).
This video shows a simple AR scene running image tracking. The left side is the
Hierarchyview, the middle is theSceneview, and the right is theGameview. The video was recorded in Unity editor'sPlaymode using simulated running data. The content of theGameview is the same as what users see in the real world on their phones. 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 position and orientation trajectory of the camera over the past period. 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 buses).
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 marker in the
Gameview still fits perfectly on the card.
For ease of understanding, the display of the ImageTarget gizmo was turned off in both videos above, 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 scenarios, this motion 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 determining this center during session operation is called the center mode. The behavior of targets varies under different center modes:
In SessionOrigin center mode, targets cannot be moved arbitrarily.
SessionOrigin mode can only exist in scenes with motion tracking.
Although this mode works well in simple scenes like the previous ones to demonstrate the movement of targets and cameras in reality, it is not commonly used in actual AR scenarios. In this mode, the session controls the movement of targets, and due to motion tracking or calculation errors in AR functions themselves, it is difficult to ensure that targets are completely fixed. At this point, the content root node must follow the target's movement, which may affect content behavior (such as the physics system) in the Unity system.
In FirstTarget or SpecificTarget center mode, if the target is exactly the object selected as the center, it can be moved arbitrarily.
Generally, 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 scene is moving.
In FirstTarget or SpecificTarget center mode, if the target is not the object selected as the center, and in Camera center mode, targets cannot be moved arbitrarily.
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 a 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 during simultaneous tracking should be fully considered, and content strategies should be reasonably adjusted.
For details about center modes and the movement of objects within scenes, please refer to: Center mode.
State of target
The state of a target reflects its recognition and tracking status in the current session. Common states include:
- Tracked: The target has been successfully recognized and tracked. AR applications can overlay virtual content on it, and the content will fit the object in the real world.
- Not Tracked: The target is currently not recognized or tracked. If AR applications still overlay virtual content on it, the content will not fit the object in the real world.
At the same time, when the state changes, you can respond through these events:
- TargetFound: Triggered when the target is successfully recognized and tracked.
- TargetLost: Triggered when the target loses its tracked status.
Lifecycle of target
In Unity AR scenes, targets are usually managed by corresponding frame filter components. The frame filter processes image data from the frame source and recognizes and tracks targets within it. The lifecycle of the frame filter relies on the session. Although implementations of different AR functions may vary, in most cases, when the session starts, targets are loaded and then controlled by the session. When the session stops, targets are unloaded and remain in place until used by the next session or manually deleted.
Next steps
- Try Obtaining target state
- Try using corresponding targets in various AR functions