Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to run scene without displaying it?

Discussion in 'Editor & General Support' started by cris177, Aug 25, 2022.

  1. cris177

    cris177

    Joined:
    Oct 8, 2021
    Posts:
    8
    Hello! I'm a long time developer but very new to unity.

    I'm not sure how to phrase this which is possibly why I couldn't find the solution googling.

    I have a scene where resources are being mined, and I would like this to always be happening in the background (sometimes in the foreground as there are also interactive elements and UI in this scene).

    I have other scenes that I would like the player to experience while their resources increase due to the main scene being run.

    I don't want to reinvent the wheel here, so I wanted to know how this kinds of things are usually managed. Should everything be a single scene? Or is it recommended to use some kind of complex scene management that keeps the main scene running but disables it's camera and inputs? Or is there a simpler solution that I'm missing?

    Thanks in advance!
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,009
    The real solution here is to separate the logic and data from the visuals.

    Have this mining and resource management happening on a level completely removed from any scene, and when in said scene related to this mining, just have it's visuals update to match the data side of things.

    Obviously you still need something to 'tick' this logic, and it should be pretty easy to have a lone game object in an additively loaded scene, or marked DontDestroyOnLoad to have this operation running.
     
  3. cris177

    cris177

    Joined:
    Oct 8, 2021
    Posts:
    8
    This would work, but I think it would be the hardest to implement for my case in particular given that I'd have to rewrite the whole scene.

    I'll keep it in mind for the future, but I'm looking for a way to handle already written scenes.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,009
    You're honestly better off doing a good rewrite. If your simulation (however rudimentary it may be) is built into a scene despite the need for other scenes to be present, it's going to create more and more problems down the line.

    You can't run scenes 'in the background'. You can use additive scene loading and have it present alongside other scenes, but the scene will still be there. At best you can just move the scene off to the side, but it'll still be there taking up memory.

    It'll save you more time in the long run.
     
  5. cris177

    cris177

    Joined:
    Oct 8, 2021
    Posts:
    8
    It is actually ideal if the main scene keeps itself active, this is a big scene that you come back often to, so it wouldn't be ideal to have to load it again and again. This is what I meant with "in the background", I just want it to keep running but it not interfering with the "foreground" scene.
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,009
    Well as mentioned there's no way to do that, at least not built in. If that's what you want, you'll have to put in the work to make it happen yourself. I can only see it being possible with judicious additive scene loading.