Table of Contents

Simulating with EIF files in Unity

This article explains how to use EIF files for simulation in Unity, enabling most development work on a computer and providing visual feedback.

Before you begin

Simulation uses EIF files as input, so you need to record an EIF file first:

You should also understand:

Enabling frame player for session

ARSession.AssembleOptions provides multiple ways to configure session component composition. One method is setting AssembleOptions.FrameSource to FramePlayer to enable the frame player component, allowing simulation with EIF files.

For example:

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

You can also modify this option in the editor by selecting AR Session (EasyAR) and changing the corresponding setting in the Assemble Options section of the Inspector window:

alt text

This configuration ensures the frame player component is enabled when the session starts, without selecting other frame source components.

The effect of playing EIF files with frame player is shown in this video:

This video demonstrates using frame player for dense spatial mapping on a computer. The left shows the Hierarchy view, the center shows the Scene view, and the right shows the Game view. The Game view content matches what users see on their mobile devices in the real world.

During EIF file playback, all AR feature components in the session work normally, and scene content and interaction logic also function properly. This allows most development work to be done on a computer with visual feedback.

Tip

The effect seen when playing EIF files on a computer is basically consistent with the effect on the mobile device during recording.

Important

The runtime effect when playing EIF files depends on the device used for recording and the frame source selected during recording. Therefore, when recording EIF files, use the same or similar devices as your target device to ensure consistent playback effects. Also pay attention to whether motion tracking is enabled during recording. If motion tracking is disabled during recording, it cannot be enabled during playback, and AR features relying on motion tracking (such as dense spatial mapping and Mega) won't work as on the actual device.

Playing during session startup

By default, frame player automatically starts playing EIF files when the session starts. However, you must specify the EIF file path before playback using the FramePlayer.FilePathType and FramePlayer.FilePath properties.

For example:

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

You can also modify these settings in the editor by selecting AR Session (EasyAR) and changing 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, frame player will fail to start during session initialization and output an error log:

File not found:

Manual playback

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

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

You can also uncheck the Enabled option for the Frame Player component in the Inspector window by selecting AR Session (EasyAR) in the editor:

alt text

When ready to play, use Play() to start playback.

For example:

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

Each call to Play() stops any previous playback (if active) and starts from the beginning.

Caution

When playing new data, existing scene data isn't cleared. AR component states aren't reset either - they behave as if camera data suddenly jumps from the previous stopping point to the new data starting point.

While this may not significantly affect some features, motion-tracking-dependent features (like dense spatial mapping and Mega) may enter abnormal states, impacting runtime effects. Therefore, it's recommended to restart the session to reset all AR component states before playing new data.

Pausing and resuming

Use FramePlayer.enabled to control playback pause and resume.

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

player.enabled = false;

When paused, all AR feature components stop working. Scene content and interaction logic may or may not stop, depending on the content itself. When resumed, AR feature components continue working from the paused position.

Stopping playback

Use Stop() to stop playback.

player.Stop();

After stopping, all AR feature components stop working. Scene content and interaction logic may or may not stop, depending on the content itself.

Seeking to specific time point

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

For example, jump to 5 seconds later:

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

Seeking may not start from the exact time point, depending on the EIF file encoding method and keyframe interval.

Not all EIF files support seeking. Use the IsSeekable property to check if the current EIF file supports seeking.

Note

Only EIF files recorded using H264 format with proper stop calls support seeking. If the EIF file doesn't support seeking, calling Seek(double) has no effect.

Playback speed control

Use the Speed property to control playback speed.

For example, increase playback speed by 0.1x:

player.Speed += 0.1;

Not all EIF files support speed control. Use the IsSpeedChangeable property to check if the current EIF file supports speed adjustment.

Note

Only EIF files recorded using H264 format with proper stop calls support speed control. If the EIF file doesn't support speed control, setting Speed has no effect.