Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Help Wanted MARS scene change

Discussion in 'Unity MARS' started by xhkong, Dec 12, 2020.

  1. xhkong


    Jul 2, 2020
    What's the best approach to setup MARS in multiple scenes? Shall we add MARS session/camera object to each scene? Or keep the object as DDOL?
  2. xhkong


    Jul 2, 2020
    Can someone from MARS support clarify on this? Also the issue I'm running into is that if I have different MARS sessions in two scenes, after the scene change MARS face tracking would stop working if it is triggered in the first scene.

    For example, when if a face was found in scene 1, then in scene 2 face tracking will stop working and any prefab that is supposed to attach to a face proxy will not be attached. However, if no face was found in scene 1, face tracking will still be working in scene 2 and attached prefabs will show up at the correct location.
  3. recursive


    Jul 12, 2012
    Right now, the best method is to only have one scene with a session loaded at a time, and have all of your MARS content live in that scene, as this is the only supported use case at this time.

    You still can load other content scenes (such as UI or models) additively.
    jmunozarUTech likes this.
  4. xhkong


    Jul 2, 2020
    thanks for the reply. I just want to clarify on my question a bit. I'm not trying to preserve the objects or MARS session across the scenes. I want to use MARS in two different scenes of my app. These MARS sessions can be completely independent from each other. I'm still having trouble. It seems that MARS session doesn't offload properly when a scene stops. Do you mean that MARS currently won't allow two independent scenes and we can only use MARS in one single scene even if we don't need to preserve anything across?
  5. mtschoen


    Unity Technologies

    Aug 16, 2016
    Hello! That's interesting... we haven't seen this issue. Do both scenes work independently if they're the first scene loaded? Part of our basic test app that we build to validate changes to the package involves switching scenes from world tracking to face tracking and back again. In our basic test case with a few proxies that match and then unmatch on scene unload, this works just fine.

    Here is the script that switches scenes:
    Code (CSharp):
    1. using TMPro;
    2. using Unity.MARS.Settings;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    6. namespace Unity.MARS
    7. {
    8.     public class SceneSwitcher : MonoBehaviour
    9.     {
    10. #pragma warning disable 649
    11.         [SerializeField]
    12.         TextMeshProUGUI m_Title;
    13. #pragma warning restore 649
    15. #if PLATFORM_LUMIN
    16.         void Awake()
    17.         {
    18.             gameObject.SetActive(false);
    19.         }
    20. #endif
    22.         void Start()
    23.         {
    24.             SetTitle();
    25.         }
    27.         public void PreviousScene()
    28.         {
    29.             LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
    30.             SetTitle();
    31.         }
    33.         public void NextScene()
    34.         {
    35.             LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    36.             SetTitle();
    37.         }
    39.         void SetTitle()
    40.         {
    41.             m_Title.text = SceneManager.GetActiveScene().name;
    42.         }
    44.         static void LoadScene(int index)
    45.         {
    46.             if (index < 0)
    47.                 index = SceneManager.sceneCountInBuildSettings - 1;
    49.             if (index >= SceneManager.sceneCountInBuildSettings)
    50.                 index = 0;
    52.             // We assume each scene loads a "fresh state" so unpause before switching scenes
    53.             MARSCore.instance.paused = false;
    54.             SceneManager.LoadScene(index);
    55.         }
    56.     }
    57. }
    The `MARSCore.instance.paused = false;` isn't entirely necessary. It's just there in case you paused things in the scene using a different UI element not represented in this script.

    Can you share your project or a test project that replicates the issue you are seeing? It's possible that you're hitting a specific edge case that doesn't survive scene reloads properly.
    imaniom and jmunozarUTech like this.
  6. xhkong


    Jul 2, 2020
    @mtschoen I created a very simple project to demo this issue. You can easily recreate in 5 mins with the following setup. Two scenes, Scene1 and Scene2 with identical setup as below: I added the default MARS Session and the FaceMask preset from the MARS->Preset->Face Mask. Then attach any prefab to this face mask. In my case, I attach a pair of glasses. Then Add a Button to trigger scene change with SceneManager.LoadScene().

    Before the the button was pressed, the Glasses would show up on user's face. After the button was pressed, the Glasses is not there anymore.

    Here is the complete setup of my testing: Device iPhone X, iOS 14.2, MARS 1.2, Unity 2019.4.15f1