Search Unity

Cinemachine and non-CM cameras in same scene

Discussion in 'Cinemachine' started by syscrusher, Jun 13, 2018.

  1. syscrusher

    syscrusher

    Joined:
    Jul 4, 2015
    Posts:
    1,104
    I have solved this problem, but I wanted to report it as a possible CM issue.

    The situation: My scene has three CM Brains, on three different actual cameras, and a number of CM Virtual Cameras of various sorts. They are broken down by layers and culling masks into the following functional areas:
    • Main Camera Layer -- contains the Main Camera with its CM Brain, plus a fairly complex character camera rig that uses a State Driven VCam and several sub-rigs to allow the player to toggle between first, third, and free-look views. Both the physical camera and the entire GameObject hierarchy containing all the nested VCams are all on this layer. The culling mask is set as follows:
      • In First Person mode, it shows everything except layers Player, Weapon, and map markers.
      • In Third Person and Free Look modes, it shows everything except map markers.
    • Map Camera Layer -- contains an orthographic top-down camera locked (with some damping) to the player's XZ position and rotation, with an invariant Y. This camera's culling mask includes map markers, default and terrain layers only, and has some post FX for color grading. There are dedicated cameras and VCams for the map markers and for the map itself, because my post FX on the map desaturate its colors, which is not what I want for the map markers. There's a small performance hit having the markers render on two cameras, but it's not measurable in this scene as there are only about 20 markers. I could put the markers on a dedicated layer, but that's more trouble than it's worth. The two CM Brains involved here control cameras that are literally identical in position and frustum.
    • Weapon Layer -- in first person mode only, this contains an additional camera with a CM Brain, plus a VCam, in the role of FPS weapon camera as is common in many FPS controllers. The player's weapons and weapon attachment point (which is a GameObject child of the hand but is not part of the skeleton) are all on the Weapon layer. (Note: NPC weapons, being always rendered in third person, are not on the Weapon layer.)
    The weapon camera was the problem. When I originally set this up, since it was just a strict follow object with no need for damping or other spiffy motion tricks from CM, was not a CM VCam but just a Camera with itself and the three GameObjects it renders all being on a dedicated layer.

    What I found was that in many cases this camera, although enabled and with a high depth setting, was simply not rendering in the game view, either in the Editor or in standalone builds. In the Editor, though, I could reliably make this camera start rendering by selecting it in the Hierarchy while the game was running, or before starting the game. Absent it being selected, it would work sometimes but not always, and sometimes would be missing at first and then would mysteriously start working during the play test. It was hard to debug this because of a sort of Heisenberg principle -- if I select the weapon cam in the inspector to understand what was wrong, I would immediately clear the bug condition.

    I hypothesized that this was some strange interaction between CM and non-CM cameras, and modified my scene to use another CM Brain and a simple target-locked VCam for the weapon camera. All is working correctly now -- well, I'm still messing with the optics, but the *rendering* process is fine.

    Again, I've got the problem solved, but thought I should post this in case someone else runs across it. If I get to the point where I can make it non-intermittent I'll submit a bug report, but right now that would probably just be wasting someone's time at Unity Tech.
     
    Adam_Myhill likes this.