Table of Contents

Session flow control

During session operation, sometimes it's necessary to modify session components, requiring stopping and restarting the session. Occasionally, you might also need to stop certain outputs from the session. This article explains how to control session operation flow.

Before you begin

Session assembly

Assembly is typically triggered automatically when starting a session.

The following code implicitly executes the assembly process:

Session.StartSession();

Sometimes, such as when needing to check availability and device support in advance, you can manually trigger session assembly using Assemble():

StartCoroutine(Session.Assemble());
Note

Assemble() returns a coroutine, which must be started via StartCoroutine(IEnumerator).

Starting session

AutoStart controls whether the session starts automatically. If AutoStart is true (default value), the session starts automatically during MonoBehaviour.Start().

Sessions can also be started manually by first setting AutoStart to false. Then use StartSession() to start the session:

Session.StartSession();

Stopping session

Use StopSession(bool) to stop the session:

Session.StopSession(keepLastFrame);

The keepLastFrame parameter controls whether to retain the last frame's physical camera image after stopping the session. This is useful when switching between different sessions to avoid screen flickering.

Note

keepLastFrame only works for sessions where EasyAR handles rendering. Generally, this parameter is invalid when using AR Foundation or head-mounted displays.

Stopping session output

During session operation, use enabled to control session output.

The following code stops all session output. The session remains running but won't update any content (including physical camera images rendered by EasyAR and all node transforms controlled by EasyAR):

Session.enabled = false;

Stopping session from rendering physical camera images

Use ARAssembly.CameraImageRenderer to control physical camera image rendering.

The following code stops physical camera image rendering:

if (Session.Assembly != null && Session.Assembly.CameraImageRenderer.OnSome)
{
    Session.Assembly.CameraImageRenderer.Value.enabled = false;
}

Note that you must first check whether ARAssembly.CameraImageRenderer exists.

Note

ARAssembly.CameraImageRenderer only works in sessions where EasyAR handles rendering. Generally, it's invalid when using AR Foundation or head-mounted display SDKs, where those platforms handle physical camera rendering.

Next steps