Pausing and Restarting Mars Session

After reading a couple other threads about this I attempted to implement a few of the solutions with no favorable resolution. Currently we are trying to “Toggle Off” the Physical Camera on an iPhone when we are on a UI screen.

The 2 Posts I’ve Read on this topic: Turn Off Mars Camera and Reset MARS
We originally thought turning off the ARSessionOrigin components, or even the ARCamera would fix the problem however neither work.

I am pretty sure I’m close, but the issue I’m reaching currently is that I am using the following code from one of the forum posts:

using System;
using Unity.MARS.Providers;
using Unity.MARS.Settings;
using Unity.XRTools.ModuleLoader;
using UnityEngine;

namespace Unity.MARS
{
    public class SessionUI : MonoBehaviour, IUsesFunctionalityInjection, IUsesSessionControl
    {
        IProvidesFunctionalityInjection IFunctionalitySubscriber<IProvidesFunctionalityInjection>.provider { get; set; }
        IProvidesSessionControl IFunctionalitySubscriber<IProvidesSessionControl>.provider { get; set; }

        void Awake()
        {
            // Only necessary if this script isn't already in the scene when you press Play
            this.EnsureFunctionalityInjected();
        }

        public void TogglePaused()
        {
            var marsCore = MARSCore.instance;
            var wasPaused = marsCore.paused;
            marsCore.paused = !wasPaused;
            if (wasPaused)
            {
                this.ResumeSession();
            }
            else
            {
                this.PauseSession();
            }
        }
    }
}

But I need to be able to Call this inside my GameManager.cs file when needed.

This is how I’m declaring it in the GameManager.cs file:

(This script is also “using Unity.MARS;”)

    public SessionUI session;

I’m implementing it like this:

session.TogglePaused();

However, the issue I’m getting is that since this script “SessionUI” has that void Awake() function to not worry about linking it as the article stated. When I play my scene however and the editor hits line 194 (the first time session.TogglePaused(); is used and hits this error:

NullReferenceException: Object reference not set to an instance of an object
GameManager.Start () (at Assets/Scripts/GameManager.cs:194)

Any ideas to fix this?

Without seeing your GameManager.cs file it’s hard to say what’s going on here. Is it trying to access session which has not been initialized?

If you file a bug report from your project from the Help menu that will let us have a look at what is going on.