Control the Mega tracking process
This article explains how to control various functions and parameters in the Mega tracking process to meet the needs of different application scenarios.
Before you begin
Adjust device support level
The MegaTrackerFrameFilter.MinInputFrameLevel property of MegaTrackerFrameFilter is used to specify the minimum device level supported by Mega.
![]()
Mega can run on almost all types of frame data sources, but different frame data sources have different impacts on tracking performance.
By default, Mega will select the highest-level frame data source supported by the device for tracking. The session supporting Mega with default configuration has already configured frame data sources supporting 6DoF and 5DoF.
To support a certain level of frame data source during Mega operation, two conditions must be met:
- The required frame data source is in the optional frame data source group of the session.
- MegaTrackerFrameFilter.MinInputFrameLevel is greater than or equal to the CameraTransformType level of the required frame data source.
For example, to support 3DoF tracking in the default session, you need to:
- Add ThreeDofCameraDeviceFrameSource to the frame data source group of the session.
- Modify MegaTrackerFrameFilter.MinInputFrameLevel to ThreeDof.
Another example, to remove 5DoF tracking support in the default session, you need to:
- Remove InertialCameraDeviceFrameSource from the frame data source group of the session.
- Modify MegaTrackerFrameFilter.MinInputFrameLevel to SixDof (even if not modified, 5DoF will not be used because there is no 5DoF frame data source).
If no suitable frame data source is available, session assembly will fail.
Track target management
When using Mega, it is necessary to specify the target, i.e., block, used by MegaTrackerFrameFilter.
Block source control
In most cases, it is recommended to keep the default configuration, which is to import blocks using Mega Studio in the editor.
Select the Mega Tracker object under the session, and the Block Root Source option should remain as External (default).
![]()
At the same time, you need to specify Block Root as the MegaBlocks object in the scene.
![]()
Modifying the Block Root Source option allows you to specify other block source methods. For example, when importing data using ema, you usually choose the Internal or Mixed option.
In the script, you can modify BlockHolder.BlockRootSource to achieve the same effect.
Multi-object tracking control
In most usage scenarios of Mega, there is no need to use multiple targets. Before mastering how to avoid mutual interference between multiple blocks, it is recommended to place only one block in a positioning library.
Tip
In principle, Mega calculates the device's position in all blocks, rather than selecting the blocks seen by the device from the positioning library. Improper use may lead to performance degradation due to data confusion and other reasons.
Select the Mega Tracker object under the session, and modify the Multi Block option to enable or disable the multi-object tracking function.
![]()
In scripts, you can modify BlockHolder.MultiBlock to achieve the same effect.
Warning
Generally, only one block can exist in a positioning library at the same time.
Modifying the multi-object configuration will affect tracking performance and is generally not recommended. Please use it under the guidance of EasyAR technical support.
If this configuration has been modified during the application execution, be sure to mention this when providing feedback to EasyAR.
Understand the current system state
In the default session configuration, UI messages will be displayed on the screen, containing information about the Mega tracking status.
When localization is successful, the Mega Block will include the Found status text along with the name and ID of the currently tracked block:
![]()
When localization fails, the Mega Block will include the NotFound status text:
![]()
Tip
NotFound is a normal state and frequently occurs during the entire Mega operation. When this state appears, tracking is still ongoing. Typically, no special handling is required for the NotFound state in application development.
Using the MegaTrackerFrameFilter.LocalizationRespond event, you can obtain the current localization status to determine whether the system has found the tracking target.
The following code demonstrates how to use this event and common exception states that applications need to be aware of:
private void Awake()
{
megaTracker.LocalizationRespond += HandleLocalizationStatusChange;
}
private void HandleLocalizationStatusChange(MegaLocalizationResponse response)
{
var status = response.Status;
wakingUpCount = status == MegaTrackerLocalizationStatus.WakingUp ? wakingUpCount + 1 : 0;
if (wakingUpCount >= 5)
{
// The service is waking up, and the end user needs to wait
}
if (status == MegaTrackerLocalizationStatus.QpsLimitExceeded)
{
// QPS limit exceeded, which may randomly cause localization failures for end users (overall tracking quality degradation)
// Generally, you need to pay to increase the QPS limit to ensure tracking quality under the current user volume
}
if (status == MegaTrackerLocalizationStatus.ApiTokenExpired)
{
// Token expired, which only occurs when using the Token interface to access the service
// To address this issue, the application needs to request a Token from its backend and call MegaTrackerFrameFilter.UpdateToken to update it
}
}
If the application frequently encounters the MegaTrackerLocalizationStatus.RequestTimeout state, it usually indicates poor network conditions for the device connecting to the service. It is recommended to optimize the network environment to improve tracking quality. In scenarios where network conditions cannot be improved, consider increasing the request timeout duration.
Note
The pose returned by localization cannot be obtained through this event.
In fact, the pose returned by localization is not needed in application development. EasyAR will calculate a more accurate pose using local algorithms after localization and return it to developers for use. This pose is already reflected in the block's transform. For more details, refer to Obtain session operation results.
Pause and resume
Mega's tracking and positioning functions can be paused and resumed separately.
Pause tracking
Set MegaTrackerFrameFilter.enabled to false to pause tracking.
By default, after tracking is paused, all content under the block node will be hidden.
Pause localization
Set MegaTrackerFrameFilter.ResultPoseType.EnableLocalization to false to pause localization.
Warning
Pausing localization may affect tracking performance and is generally not recommended. Please use it under the guidance of EasyAR technical support.
If localization has been paused during the application execution, be sure to mention this when reporting issues to EasyAR.
Service and request control
You can control the behavior of request services by modifying the parameters of the MegaTrackerFrameFilter component.
Request interval and timeout
Select the Mega Tracker object under the session, and modify the options under Request Time Parameters to adjust the request service interval and timeout.
![]()
In the script, you can modify MegaTrackerFrameFilter.RequestTimeParameters to achieve the same effect.
Warning
Modifying the request interval will affect the tracking effect, and it is generally not recommended to modify it. Please use it under the guidance of EasyAR technical support.
If the request interval has been modified during the application execution, please make sure to mention this when providing feedback to EasyAR.
Switch localization database
Use MegaTrackerFrameFilter.SwitchEndPoint(ExplicitAddressAccessData, BlockRootController) to switch the localization database at runtime. When using this interface, the camera view and session will not be interrupted.
Related topics
- AR Session Best Practices for Mega introduces how to create and configure an AR session for Mega
- Adding Mega Tracking Targets introduces how to add Mega's tracking target block and how to load block models in the Unity editor to assist development
- Adding a Group of Frame Data Sources introduces how to modify the session's frame data source group
- Obtaining Session Runtime Results introduces how to obtain the tracking results of the session component
- UI Messages introduces how to use UI messages to display session status