Search Unity

Question Pausing and Restarting Mars Session

Discussion in 'Unity MARS' started by jcahn, Jan 8, 2022.

  1. jcahn

    jcahn

    Joined:
    Dec 20, 2021
    Posts:
    3
    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:

    Code (CSharp):
    1. using System;
    2. using Unity.MARS.Providers;
    3. using Unity.MARS.Settings;
    4. using Unity.XRTools.ModuleLoader;
    5. using UnityEngine;
    6.  
    7. namespace Unity.MARS
    8. {
    9.     public class SessionUI : MonoBehaviour, IUsesFunctionalityInjection, IUsesSessionControl
    10.     {
    11.         IProvidesFunctionalityInjection IFunctionalitySubscriber<IProvidesFunctionalityInjection>.provider { get; set; }
    12.         IProvidesSessionControl IFunctionalitySubscriber<IProvidesSessionControl>.provider { get; set; }
    13.  
    14.         void Awake()
    15.         {
    16.             // Only necessary if this script isn't already in the scene when you press Play
    17.             this.EnsureFunctionalityInjected();
    18.         }
    19.  
    20.         public void TogglePaused()
    21.         {
    22.             var marsCore = MARSCore.instance;
    23.             var wasPaused = marsCore.paused;
    24.             marsCore.paused = !wasPaused;
    25.             if (wasPaused)
    26.             {
    27.                 this.ResumeSession();
    28.             }
    29.             else
    30.             {
    31.                 this.PauseSession();
    32.             }
    33.         }
    34.     }
    35. }
    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;")

    Code (CSharp):
    1.     public SessionUI session;
    I'm implementing it like this:
    Code (CSharp):
    1. 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?
     
    Last edited: Jan 9, 2022
  2. CiaranWills

    CiaranWills

    Unity Technologies

    Joined:
    Apr 24, 2020
    Posts:
    199
    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.