Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Can I use 2 camera with Cinemachine Brain?

Discussion in 'Cinemachine' started by fmacro, Jul 14, 2017.

  1. fmacro

    fmacro

    Joined:
    Mar 24, 2017
    Posts:
    4
    When I use cinemachine in two player game, I did not know how to use two camera with cinemachine brain.
    Do you have a way to use two camera ?
     
    Last edited: Jul 14, 2017
  2. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    392
    Just create second camera and add it's own Cinemachine Brain.
     
  3. fmacro

    fmacro

    Joined:
    Mar 24, 2017
    Posts:
    4
    I'm sorry I didn't make it clear enough.
    I want to use two camera with differ virtual camera.
    I added second Cinemachine Brain, both camera followed same virtual camera.
     
    Last edited: Jul 15, 2017
  4. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    392
    @Adam_Myhill Any way to set it up?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,636
    From the user docs:

    You can set up a multi-camera split-screen with Cinemachine 2.0:
    1. Make 2 Unity Cameras, let's call them Camera A and Camera B. Give each one its own CinemachineBrain, and set up their viewports.
    2. Now make 2 virtual cameras to follow the players. Assign those virtual cameras to different layers. We’ll call them layer A and layer B.
    3. Go back to the two Unity cameras, and set their culling masks so that the Camera A excludes layer B and the Camera B excludes layer A.
    4. That’s it! Camera A will be driven by virtual cameras on layer A, and camera B will be driven by virtual cameras on layer B. They will do their blending etc independently.
    5. Extend this idea to as many layers and cameras as you like.
     
    Last edited: Nov 29, 2017
  6. fmacro

    fmacro

    Joined:
    Mar 24, 2017
    Posts:
    4
    This problem was resolved thanks to your support!
    Thank you for your help!
     
  7. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    370
    Does this work for showing the same scene from different angles on a split-screen?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,636
  9. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    370
    Tried that, but the cameras only show whatever exists in their assigned layer. I must be missing something, but don't know what it is :)
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,636
    Make new layers for the vcams. Have your Cameras see everything except the other guy's vcam layer.
     
  11. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    370
    Wow! Thanks. I can't believe how good Cinemachine is and I'm probably using less than 10% of what it can do.

    PS. Do you think
    "Go back to the two Unity cameras, and set their culling masks so that one camera sees layer A but not layer B... "

    should say

    "Go back to the two Unity cameras, and set their culling masks so that one camera excludes layer B ..."
     
    Adam_Myhill and Gregoryl like this.
  12. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    370
  13. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    392
  14. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    370
  15. iwaldrop

    iwaldrop

    Joined:
    Sep 3, 2012
    Posts:
    8
    @Gregoryl Wow, that is unexpectedly easy. It sure would be great though if a single camera could be used on several layers. Perhaps moving the check to a layer mask field on either/both the virtual camera/brain would allow a single virtual camera to be used by brains on separate layers.

    Example:
    * vcams 1 and 2 where 1 applies to all layers, and where 2 applies to only one; vcam 2 is inactive
    * two unity cameras assigned to corresponding layers, each with a brain component attached
    * vcam 2 is activated and brain on layer 2 transitions to vcam 2 while brain on layer 1 remains unchanged

    As of now it seems the only way to achieve this effect is to duplicate one vcam between two layers, and reducing this duplication seems like it would facilitate a smoother experience when tweaking and maintaining camera angles.
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,636
    @iwaldrop I think you can get what you're looking for by using a third vcam layer:
    • Brain 1 sees vcam layers 1 and 3
    • Brain 2 sees vcam layers 2 and 3
    • vcam 1 is on layer 3, vcam 2 is on layer 2
    • Initially vcam 1 is active, both brains see it
    • When vcam 2 is activated, only Brain 2 will transition
     
  17. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    128
    hi guys, hi @Gregoryl, I have a kind of similar setup to what is asked here, I have a "security room" where you have multiple screens, each one shows the renderTexture that different cameras have assigned, basically you can see multiple cameras rendering at the same time, which is similar to split screen rendering.

    I have two problems with the "set opposite cameras in different non intersecting layers" approach:

    the first one is the obvious, once you get more than 4-5 cameras managing the layers exclusions and inclusions starts to be a mess, cam A should exlcude B,C,D,E, but not exclude other important layers, cam B should exclude A,C,D... etc, you get what I mean.

    The second problem is that this approach is very limited to the small amount of layers Unity has, while we have less than 32 layers, some of them are already taken for physics exclusions, lighting, rendering, etc. so this is not really scalable.

    would it be too hard to have an option to switch from the current way the Brains compute their affecting virtualCams to an approach where you explicitly set a List<CinemachineVirtualCam> in the inspector or through code in each brain (note that I imagine this as an optional boolean that switches between the two algorithms)?.
     
  18. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,636
    Hmmm... no immediate plans for this. However, I think there is a way with the current code.

    The CM brain has an API to override its vcam selection mechanism. This is what timeline uses. You can write a script that has its own vcam selection logic (possibly based on a list of vcams), and uses the brain's override API to drive it.
     
    Cleverlie likes this.
  19. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    128
    thanks, I think thats a good starting point for me, is this API documented or is it internal? I had a look at the docs but I didn't found anything at first sight, maybe you can point me in the direction of this feature? thanks again
     
  20. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,636
    Yeah it's marked internal and not documented, although it does have XML doc in the sources.
    Will look at promoting it to public for next release.

    You need to check out CinemachineBrain.SetCameraOverride() and CinemachineBrain.ReleaseCameraOverride().
    For a usage example see CinemachineMixer.cs.

    If you go this route, you'll have to manage your own blending, the way timeline does.
     
  21. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    128
    roger, will check that out, thanks!