Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    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:
    417
    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:
    417
    @Adam_Myhill Any way to set it up?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,688
    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!
     
    ModLunar likes this.
  7. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    444
    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:
    3,688
  9. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    444
    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:
    3,688
    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:
    444
    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 ..."
     
    ModLunar, Adam_Myhill and Gregoryl like this.
  12. username132323232

    username132323232

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

    JakubSmaga

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

    username132323232

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

    iwaldrop

    Joined:
    Sep 3, 2012
    Posts:
    9
    @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:
    3,688
    @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:
    209
    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:
    3,688
    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:
    209
    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:
    3,688
    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:
    209
    roger, will check that out, thanks!
     
  22. Remolino

    Remolino

    Joined:
    Oct 21, 2012
    Posts:
    5
    Thank you. Save my a lot of time
     
  23. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    303
    Yep, minus the fact that this API is now internal. I do wonder what was the reasoning behind gating it off? Relying fully on layers to drive the camera behaviour is, IMO, a very flimsy tactic.
     

    Attached Files:

  24. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    62
    Will this layer technique work for the same camera viewport? I have a FP arms that i want to prevent culling inside walls and enemies. To achieve this with regular cameras I just set one of them to skybox and the other one to clearflags, assigning my arms to a specific layer and it works great, but apparently cinemachine wont work the same way. Is this achievable somehow?
     
  25. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,688
    Cinemachine just pushes the camera around. Layering techniques will continue to work.
     
  26. shreyamathur651

    shreyamathur651

    Joined:
    Dec 13, 2019
    Posts:
    6
    Create Second Camera
     
  27. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    I tried this on Unity 2018.4 and it doesn't word.
    I'm using the LWRP, not sure if it affects this.
     
  28. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,688
    Should work. You're probably doing it wrong.
     
  29. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    341
    @totsboy This video might help, let us know how it goes

     
    mindfulmx likes this.
  30. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    Thank you for the helpful reply.

    I had already seen the video. I tried doing the same but it's not working, not sure what I am missing. I captured some screenshots of the setup, so maybe you can spot what's wrong. In my case, one of the cameras is supposed to render a rain FX, while the normal camera show gameplay.
     

    Attached Files:

    • SS1.jpg
      SS1.jpg
      File size:
      415.2 KB
      Views:
      122
    • SS2.jpg
      SS2.jpg
      File size:
      387.7 KB
      Views:
      122
    • SS3.jpg
      SS3.jpg
      File size:
      405.1 KB
      Views:
      106
    • SS4.jpg
      SS4.jpg
      File size:
      398 KB
      Views:
      114
  31. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,688
    Happy to be more helpful now that you've provided a little more info than "it doesn't work" ;)

    It looks as though your vcam layers and camera culling masks are set up correctly for CM to drive one camera with one set of vcams, and the other camera with the other set.
    Are the viewports of the cameras also set up correctly?
    If you disable the CM brains and position the cameras manually, do they render correctly? If not, then you probably have the rendering incorrectly set up, and should perhaps ask on the graphics forum.
     
  32. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,688
    Looking again at your setup, it strikes me that you don't need to use CM for your effects layer. Just use a single CM brain on the Camera that you want to drive with CM, and have a simple camera, with no vcams, rendering the effects. That camera never needs to move, so you don't need CM for it.
     
  33. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    That was the first thing I tried, but since it did not work I thought I had to use CM.
    I think it has something to do with the LWRP. I'll try the graphics forum, thanks for the help!
     
  34. Northmaen

    Northmaen

    Joined:
    Jun 23, 2015
    Posts:
    13
    Hey, I'm trying to use the new Input Manager with Cinemachine and i can't get it to work properly. In a Two player environment, the brain follows only the second Virtual Cam (Player 2). Since the entire rig (player and camera) are prefabs, instantiated by the Input Manager itself, I cannot assign different layers. How can I make those two systems works together?
     
unityunity