Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Is it possible to set where runtime instantiated providers can live?

Discussion in 'Unity MARS' started by azevedco, Jan 20, 2022.

  1. azevedco

    azevedco

    Joined:
    Mar 2, 2014
    Posts:
    34
    Hi there,
    When you hit run with MARS set up in your scene, it instantiates a bunch of gameobjects with provider components attached into the active scene. These guys here:
    upload_2022-1-20_7-31-29.png

    My concern here is, I've got a Core scene with the MARS setup, then other scenes we load into the experience. For example, if I have a scene "Kitchen" loaded in and set as active with the Core scene also loaded in, when I hit play, these providers get instantiated into my Kitchen scene. If I then unload that scene to load in another environment, I lose these providers.
    Is there a way I can specify a parent transform for these providers to instantiate under?
    I've had a look inside the MARSSession script and looks like it just instantiates them with a null parent. Hoping there's more options I'm just missing here.

    Thanks!
    - Cole
     
  2. mtschoen

    mtschoen

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    194
    Hi there! Thanks for reaching out and explaining the issue. Would it be possible for you to keep the scene with the MARSSession active at start, and then use a script to set the Kitchen scene active? That's probably the easiest way to fix this without modifying MARS.

    At the moment, the providers that are automatically set up by MARS will always go into the active scene, but the system is pretty flexible, so there's no reason why we couldn't give you more control over that. We'll need to think a bit on a proper workaround, but something you could try is to duplicate the `MARSSceneModule` script into one of your own assemblies and change the behavior to fit your use case. You can disable the existing module by finding it in `Project Settings > Module Loader` and unchecking the box for it.

    I'm pretty sure this is the module you would need to modify, although it depends on whether you're talking about providers in play/runtime vs. providers for edit mode simulation. If this is an issue in edit mode, the change is a bit more complicated.

    We can also try to come up with a way to expose a setting for what scene or parent to use for MonoBehaviour providers, so that users can solve this problem without having to duplicate/modify MARS code.
     
  3. azevedco

    azevedco

    Joined:
    Mar 2, 2014
    Posts:
    34
    Hey mtschoen, thanks for your response!
    Fortunately, the current flow between scenes on builds run perfectly as the Core scene runs first, initializing MARS, then we can go between other scenes without a problem. So the issue does fall under testing inside of Unity where...say we want to test the experience from with in the Kitchen scene, that would be loaded as the active scene with the Core scene loaded alongside it. However, say if while testing, we go from the Kitchen scene to another scene, since those providers got instantiated into the Kitchen scene, we now have lost those providers.

    We're about to make a new change too actually that will impact builds. We'd like to instantiate MARS at a later point rather than right at the start, doing so now means that we should fade the screen out, preferably when switching scenes, make Core active and initialize MARS, then load the new scene...that should work.

    Heh, but definitely, it would be way more convenient if your team could allow us to specify a parent for those providers to initialize under.

    I'll take a look at the modules, it does seem a bit intimidating at first glance, haven't seen "MARSSceneModule" in there, but i'll take a closer look.

    We're on MARS 1.4.1, by the way.