Search Unity

Camera stacking and cinemachine

Discussion in 'Cinemachine' started by Poi-son, Dec 22, 2021.

  1. Poi-son

    Poi-son

    Joined:
    Dec 22, 2021
    Posts:
    33
    Hello,

    I have seen that it is possible to stack cameras in unity as overlay cameras to use in different parts of visuals.
    What I want to know is, when you stack your cameras, how do you set up a cinemachine for each of them or do you even setup a cinemachine per camera? I'm confused about this bit.

    For example, I will use 1 camera for in-game and 1 camera for UI. Do I also setup a cinemachine for each? If so, how? As far as I know, a cinemachine virtual cam takes control of your native camera.

    The reason I'm after this is, I want to be able to try and apply different post-processing effects for each visual(in game and UI). How does one go with that?

    Thanks
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The purpose of Cinemachine is to simplify the authoring of sophisticated camera behaviours. It makes sense to use this on the main camera that is following the action, but there is normally no reason to use this on your UI camera.

    Cinemachine will take control of any native camera with a CinemachineBrain component. You can have several of these if you want to, but in your case it might make sense to create a UI camera without a CinemachineBrain, then you can just control it in the normal way.
     
    SalchipapasGames and Poi-son like this.
  3. Poi-son

    Poi-son

    Joined:
    Dec 22, 2021
    Posts:
    33
    Ahh I see! That makes more sense now.

    Also, I have seen some problems(?) when searching the old forum posts relating to using different post processing effects and values for in game display and UI. Like, one bleeds into another. Is it still relevant?
    I also had this problem with 1 camera setup. My UI post-processing "gaussian blur" spread all in to my in-game display render and whatever I did with my layers etc. I couldn't make it work the way I wanted.
    That's why I chose to use 2 cameras with 1 for each display.
    Is this ok?

    Thank you very much for the help and clarification!
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Two cameras is fine.
     
    Poi-son likes this.
  5. TSRajesh

    TSRajesh

    Joined:
    Jun 19, 2013
    Posts:
    69
    Sorry to wake up this old thread.. I couldn't get an answer anywhere..
    I use stacked cameras, not for UI but for rendering weapons (Clipping thru objects issue).
    When I switch between virtual camera, Only the main camera gets updated. The overlay camera does not. (FOV changes.. for zooming in). Any suggestions?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You could put a custom script on the second camera that monitors the first camera's FOV and applies the changes. To make that work properly, you would have to ensure that the script runs after CM Brain sets the camera, otherwise you will be using stale data from the previous frame. The best way to do that is to hook into CinemachineCore.CameraUpdatedEvent, read the current settings there and apply the appropriate modifications to your overlay camera.
     
    RemDust likes this.
  7. inget-namn

    inget-namn

    Joined:
    Jan 17, 2013
    Posts:
    1
    I ran into this problem. I solved my situation by placing the cameras and vir cameras on their own layer, and including it in the culling mask of both cameras. As the camera-only-layer only contains cameras it doesnt seem to affect anything else.

    might help?