Search Unity

How can I add a different live camera to the Cinemachine brain?

Discussion in 'Cinemachine' started by Abuscaglio, Feb 10, 2018.

  1. Abuscaglio

    Abuscaglio

    Joined:
    Sep 5, 2017
    Posts:
    46
    I have 3 main cameras for my game's main menu and Cinemachine brain is attached to each of them. I want different virtual dolly cameras attached to each of them so when I click a designated button on my main menu canvas, the current camera will disable/a new one will be enabled and will run through the assigned dolly animation. I have all my scripting and animations set up, but the brain wont let me assign different dolly cams to my different main cameras as the drag and drop field is greyed out (designed scripting logic in the brain). Is there any way to allow me free access to place the dolly cam of my choosing in this field?

    Thanks.
     
    Anebissa likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,710
    You've got the paradigm wrong. There should be only one Unity Camera, and 3 virtual cameras, each with its dolly track. You enable/disable the vcams, not the Unity camera. The brain on your single Unity camera is monitoring the virtual cameras, and it will position itself according to the current active one.

    The virtual cameras are effectively puppeteering the main camera. The greyed out field is a read-only indicator of which vcam is controlling the main camera. The brain populates that field, not you. You control this indirectly by enabling/disabling the virtual cameras.

    By default, the transition between virtual cameras will be a blend. To make this a cut instead, you need to change the "default Blend" field in the brain to "Cut".
     
  3. Abuscaglio

    Abuscaglio

    Joined:
    Sep 5, 2017
    Posts:
    46
    BINGO. But after I set the blend mode to cut, how do I designate which Vcams to disable/enable on button click? Will I have to whip up a script? Can I accomplish this through multiple On Click() events on the buttons themselves?
     
    Anebissa likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,710
    I would assume that somewhere you have a snippet of code that gets called when the button is clicked. That code would enable/disable the vcams.
     
    Anebissa likes this.
  5. Abuscaglio

    Abuscaglio

    Joined:
    Sep 5, 2017
    Posts:
    46
    Got it! I can just set an onclick() listener for the setactive function to the button with the specific vcam and no extra scripts will be necessary! Thanks for the help!
     
    Anebissa likes this.
  6. noneyabiznus

    noneyabiznus

    Joined:
    Oct 17, 2021
    Posts:
    7
    PLEASE HELP "I would assume that somewhere you have a snippet of code that gets called when the button is clicked. That code would enable/disable the vcams."

    HOW do I enable the cams in code please?
     
    Anebissa likes this.
  7. noneyabiznus

    noneyabiznus

    Joined:
    Oct 17, 2021
    Posts:
    7
    Ok I know this is an old thread, but I solved my problem so if anyone else is having the same thing this is what I did:

    public GameObject camera;

    void Update()
    {
    if (Input.GetKeyDown("2"))
    {
    camera.SetActive(true);
    }

    if (Input.GetKeyDown("1"))
    {
    camera.SetActive(false);
    }
    }

    and then link the camera to the "camera" game object slot.
     
    Anebissa likes this.
  8. Anebissa

    Anebissa

    Joined:
    Sep 3, 2022
    Posts:
    1
    Thanks a lot