Table of Contents

Simulate running with EIF files in Unity

This article explains how to use EIF files for simulation in Unity, allowing most development work to be done on a computer and visualizing the results.

Before you start

Simulation runs use EIF files as input, so you need to record an EIF file before starting:

You should also understand:

Enable frame player with session

ARSession.AssembleOptions provides multiple ways to configure the combination of session components. One way is to set AssembleOptions.FrameSource to FramePlayer to enable the frame player component, allowing simulation runs using EIF files.

For example:

Session.AssembleOptions.FrameSource = AssembleOptions.FrameSourceSelection.FramePlayer;

Alternatively, in the editor, select AR Session (EasyAR) and modify the corresponding option in Assemble Options in the Inspector window:

alt text

This way, the session will enable the frame player component upon startup and will not select other frame source components.

The effect of using the frame player to play an EIF file is shown in the following video:

This video demonstrates the effect of using the frame player to simulate dense spatial mapping on a computer. The left side shows the Hierarchy view, the middle shows the Scene view, and the right side shows the Game view. The content in the Game view is the same as what the user would see on a mobile device in the real world.

During the playback of the EIF file, all AR functional components in the session can work normally, and the content and interaction logic in the scene can also work normally, allowing most development work to be done on the computer with intuitive visual feedback.

Tip

The effect seen when playing an EIF file with the frame player on a computer is largely consistent with the effect on the mobile device when the EIF file was recorded.

Important

The runtime effect when playing an EIF file in the scene is related to the device used for recording and the frame source selected on the device at that time. Therefore, when recording an EIF file, it is recommended to use a device that is the same as or similar to the target device to ensure that the playback effect matches the effect on the target device. Additionally, it is important to pay attention to whether the motion tracking function was enabled during recording. If motion tracking was not enabled during recording, it cannot be enabled during playback, and AR features that rely on motion tracking (such as dense spatial mapping, Mega, etc.) will not work as they would on the device.

Play at session startup

By default, the frame player automatically starts playing the EIF file when the session starts, but the EIF file path needs to be specified before playback. This can be set using the FramePlayer.FilePathType and FramePlayer.FilePath properties.

For example:

var player = Session.GetComponent<FramePlayer>();
player.FilePathType = WritablePathType.Absolute;
player.FilePath = path;

Alternatively, in the editor, select AR Session (EasyAR) and modify the corresponding options in the Frame Player component in the Inspector window:

alt text

If no file is specified or the file path is invalid, the frame player will fail to start when the session starts and output an error log:

File not found:

Manual playback

To manually control the playback timing, you can set FramePlayer.enabled to false before starting the session,

Session.GetComponent<FramePlayer>().enabled = false;

Alternatively, in the editor, select AR Session (EasyAR) and uncheck the Enabled option of the Frame Player component in the Inspector window:

alt text

When you need to play, use Play() to start playback.

For example:

if (Session.Assembly.FrameSource is FramePlayer player)
{
    player.Play();
}

Each call to Play() will stop the previous playback (if any) and start playing from the beginning.

Caution

When playing new data, the existing data in the scene will not be cleared. The state of AR components will also not be reset, and they will behave as if the camera data suddenly jumps from where the previous data stopped to where the new data starts.

While this may not significantly affect some features, it could cause abnormal states for features that rely on motion tracking (such as dense spatial mapping, Mega, etc.), potentially impacting performance. Therefore, it is recommended to restart the session to reset the state of all AR components before playing new data.

Pause and resume

Use FramePlayer.enabled to control the pause and resume of playback.

For example, set FramePlayer.enabled = false to pause playback:

player.enabled = false;

When playback is paused, all AR functional components will stop working. The content and interaction logic in the scene may or may not stop, depending on the content itself. When playback resumes, the AR functional components will continue working from the paused position.

Stop playback

Use Stop() to stop playback.

player.Stop();

After playback stops, all AR feature components will stop working. The content and interaction logic in the scene may not necessarily stop, depending on the content itself.

Seek to a specific time point for playback (seek)

Use Seek(double) to seek to a specific time point for playback.

For example, seek to play after 5 seconds:

player.Seek(player.Time + 5);
Note

After seeking, playback may not start from the exact time point, depending on the encoding method of the EIF file and the keyframe interval.

Not all EIF files support seek playback. You can use the IsSeekable property to check if the currently playing EIF file supports seek playback.

Note

Only EIF files recorded using the H264 format and with normal stop recording support seek playback. If the EIF file does not support seek playback, calling Seek(double) will have no effect.

Playback speed control

Use the Speed property to control playback speed.

For example, to increase the playback speed by 0.1 times the original speed:

player.Speed += 0.1;

Not all EIF files support playback speed control. You can use the IsSpeedChangeable property to check whether the currently playing EIF file supports playback speed control.

Note

Only EIF files recorded using the H264 format and with normal stop recording support playback speed control. If the EIF file does not support playback speed control, setting Speed will have no effect.