Main menu camera versus game scene camera

How should I handle cameras across menu vs game scenes? I have a main menu scene with its own camera, and when they start a new game I load the game scene that also has a camera. The game camera has specific logic to follow the player object.

Yet when the seen switches, I briefly see a flash of a “no camera” message. Should I always have at least one camera loaded, with maybe a loading canvas display?

I’m not finding a good explanation on how I should be managing the camera this way, or if I should structure things differently?

1 Like

I’ve always just used the one ‘main’ camera across the entire runtime. This is easier to handle with Cinemachine as you can use virtual camera in lieu of actual cameras in your scene.

Namely at application start up I load and instantiate the main camera prefab, which is also marked DontDestroyOnLoad, which hangs around for the entire runtime session. I also put the Event System and its respective input module on a child game object as well. Two birds with one stone and all that.

Fading to black and what not of course provides the illusion that the camera is changing from main menu to gameplay.

Ok, that’s what I figured - thanks. So for my custom game logic that has the camera follow the player, I should attach that when the game scene loads, and remove it when the user quits back to the menu?

  1. AFAIK, "No cameras rendering” message can only be seen in the Editor, and not in the Build. You can disable this message in the Editor by right-clicking Game view tab and unchecking > “Warn if No Camera Rendering”.

  2. As @spiney199 said, you can use DontDestroyOnLoad feature,
    I created a tutorial for using this.

1 Like

Attaching the camera when the scene loads and removing it when returning to the menu would work. It may create some headaches for you, though, if you are manually managing objects from Don’t Destroy On Load in separate scenes like that.

For example, if you later want to add a third scene. You’d still have a camera floating around in DDOL. You’d need to decide (based on what the new scene is) if you want to

  1. attach it to a new player object,
  2. detach it altogether, etc.
    Then you end up with logic that depends on what scene you are transitioning FROM, and what scene you are transitioning TO, and it quickly becomes hard to deal with.

@spiney199 mentions above that you could make this easier with Cinemachine, which is Unity’s camera package. In your menu, you can have a Virtual Camera positioned where you want it to be. In your gameplay scene, have a Virtual Camera that uses the player follow logic you have already written. The main camera, that exists in DDOL, needs a CinemachineBrain component on it. It will then automatically position itself to align with the virtual cameras in your different scenes.

The idea is to separate the responsibilities of:

  1. Position the camera in the scene (this is what your cinemachine cameras do, and you can have several of them across several different scenes).
  2. Render the game (this is what your main camera does, and you can have just one that persists throughout the whole game in DDOL).

There are additional considerations – you may want to fade to black during the transition between scenes, or adjust the blends on the CinemachineBrain to avoid a long interpolation between the positions in the different scenes. But doing this will make the setup more scalable if you have additional plans for the game beyond the two scenes.

it think you should keep the separate if you don’t need fancy transitions from the gameworld to the menu, like for example if you open the menu the game pauses and the camera zooms back to a far view above the gamearea and when you close the menu it zooms in back into the action.

if you don’t needs something like that, just load the menu scene (or have it always in memory but hidden from view if it doesn’t have heavy assets that can waste the memory) show that scene then remove it.

there is nothing wrong in going with cinemachine route having it jumping or transitioning from camera to camera but if you don’t need all the fancy stuff is a waste of time