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. Dismiss Notice

Analysis Paralysis due to camera/scenes/loading order

Discussion in 'Editor & General Support' started by djweaver, Oct 10, 2020.

  1. djweaver

    djweaver

    Joined:
    Jul 4, 2020
    Posts:
    105
    TLDR version:
    I'd like to have a camera for a persistent scene that renders a fade transition over any given scene that is loaded additively, while still being able to display and interact with the UI canvases of each child scene.

    Long version:
    Right now I have a scene called "Main" that has a couple of monobehaviours that handle loading new scenes, playing a transition animation, and handling audio. This scene is persistent, and contains nothing else. The idea is that it is the entry point of the program and it loads and transitions to scenes as necessary additively (to itself) with each child scene replacing the last (unloading the current scene, and loading the next scene).

    As is, there is no camera on the Main scene. The transition canvas with the fade screen is set to Overlay and when I call the method to load the next scene, the white color fades in, a loading bar displays, the current scene is unloaded, the next scene is loaded, and then the white color fades out, revealing the new scene.

    This works fine and dandy but with a catch... there is this split second where the loading bar is being displayed but there is no active camera, because the "from" scene gets unloaded, the "to" scene hasn't yet loaded, and the Main scene has no camera.

    This can be seen in the first few seconds of my little demo vid when I hit the "Time Attack" menu button. If you pay close attention, you see the load bar flicker briefly and over it is the message from Unity Editor that I have no active camera. This happens for a split second only because I don't have many assets being loaded (currently) and load time is snappy.


    If I put a camera on the Main scene and use the transition canvas on that camera, cameras from other scenes won't render the UI from their respective scene as their UI canvases have no reference to the camera in the Main scene. I can disable the camera from the Main scene and use it only during the transition phase, and that will get me the nice fade to white transition, but the UI elements from scenes being loaded won't display because their canvases are linked to their respective cameras. Then, when the transition is finished and the Main camera is disabled, they will pop in instantly rather than fading in with the transition. Without some kind of magical dynamic reference to the camera in the Main scene from within each child scene (if that is even possible) this won't work.

    I'm just really confused as to what I need to do to get the functionality I desire, and frankly, don't even now how to ask or what to ask for... whether this be a referencing cameras issue or a poor design choice overall. I feel like I'm so close to what I want and I hate to deviate away from my current model, but that one tiny issue of not having a camera for that split second is unacceptable.
     
  2. kryzodoze

    kryzodoze

    Joined:
    Nov 6, 2013
    Posts:
    21
    If you do exactly what you were doing ("I can disable the camera from the Main scene and use it only during the transition phase, and that will get me the nice fade to white transition, but the UI elements from scenes being loaded won't display because their canvases are linked to their respective cameras"), but change the Clear Flags on that "main scene camera" to 'Don't Clear', and set it's Culling Mask to only the layer that your UI lives on (in this case maybe put the loading transition UI on it's own layer so it's guaranteed to only render that). Also bump up the Depth on the camera to something higher than your other cameras. This should put it in front, only rendering the loading graphic, and everything else will be drawn normally. You might want to remove the loading graphic's layer from the culling mask of the other cameras also.

    Alternatively, you could just GameObject.Find(<main camera's name>) in the scenes that you load to get a handle to the main scene's camera, but that is slow. Also a bit hacky imo (if you change the camera name you have to reflect that everywhere).