Turn Off MARS Camera

Kind of :slight_smile:

What you posted seems like it should work, but I was talking about having this all be one script. The “Hidden subscriber” pattern used in the example is also a bit more complicated than what you need here. I haven’t been able to test this, but the following code should work, as long as you don’t call TogglePaused until the camera has fully initialized. If you want the app to start with the camera disabled, you can do that by disabling auto-load in XR Management settings. Happy to go into more detail there if that’s what you’re after.

Please try this and see if it works for you

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();
            }
        }
    }
}
1 Like