Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to switch between cameras?

Discussion in 'Cinemachine' started by twinmatrix, Jul 27, 2018.

  1. twinmatrix

    twinmatrix

    Joined:
    Sep 6, 2012
    Posts:
    38
    I just read the blog post tutorial and they mention that you should set up multiple cameras and switch between them. But how are we supposed to do this? I know how to turn off a camera and turn another one on, but surely that can't be what they mean? There must be some kind of smooth transition system?

    Thanks. :)
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,241
    Indeed there is. You have one Unity camera, with a Cinemachine Brain component. That stays on all the time.

    Then, you have multiple Virtual Cameras that you activate and deactivate as needed. Simply activate/deactivate their GameObjects. The Brain will take care of the blending.
     
    Apeles, AJDB and MoisesMM like this.
  3. anthony-pinskey

    anthony-pinskey

    Joined:
    Dec 23, 2016
    Posts:
    17

    So would that be as simple as writing this?
    Code (CSharp):
    1. gameObject.SetActive(bool);
     
    Apeles likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,241
    Yes.
    You can also deactivate the outgoing vcam at the same time.
    Control the transitions from the Brain:

    upload_2018-7-27_14-15-15.png
     
    anthony-pinskey likes this.
  5. Lee_Kaili

    Lee_Kaili

    Joined:
    Sep 24, 2019
    Posts:
    3
    Hi, may i know can i have one main camera without a Cinemachine Brain component, second camera with Cinemachine Brain component and multiple virtual camera? and switch between them, is it will work
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,241
    Yes it will work. The vcams will control the CMBrain camera, the other camera is free.
     
    Lee_Kaili likes this.
  7. Lee_Kaili

    Lee_Kaili

    Joined:
    Sep 24, 2019
    Posts:
    3
    OK Thanks, I will try to figure out
     
  8. AJDB

    AJDB

    Joined:
    Aug 1, 2014
    Posts:
    14
    [QUOTE = "Gregoryl, publicación: 3577875, miembro: 1242385"] De hecho, la hay. Tienes una cámara Unity, con un componente Cinemachine Brain. Eso permanece encendido todo el tiempo.

    Luego, tiene varias cámaras virtuales que activa y desactiva según sea necesario. Simplemente active / desactive sus GameObjects. El cerebro se encargará de la mezcla. [/ QUOTE]

    Hola, ¿podría hacer lo mismo si tengo varios jugadores y cada uno con su cerebro de cámara? y una sola cámara virtual? Solo se crearía una instancia de un jugador, que se elegiría de un menú.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,241
    You can have multiple CM Brains in the scene. Each will filter vcams according to the culling mask in the associated camera. Active vcams on the visible layers will drive the brain. There is no hard link.
     
    AJDB likes this.
  10. AJDB

    AJDB

    Joined:
    Aug 1, 2014
    Posts:
    14
    [QUOTE = "Gregoryl, publicación: 6986375, miembro: 1242385"] Puede tener múltiples CM Brains en la escena. Cada uno filtrará vcams de acuerdo con la máscara de selección en la cámara asociada. Las cámaras virtuales activas en las capas visibles impulsarán el cerebro. No hay un vínculo fijo. [/ QUOTE]

    Thank you understood. Now another problem arises, and that is that the post-processing is not seen. I have created a layer for it, and everything is on the correct layer, but it does not display
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,241
    What version of post-processing are you using? And are you using HDRP or URP?
     
  12. Apeles

    Apeles

    Joined:
    May 16, 2022
    Posts:
    5
    What is the best way to switch cameras in terms of performance? Activate/deactivate their GameObjects, increase/decrease their Priority, or to use MoveToTopOfPrioritySubqueue() function?

    Thanks in advance!
     
  13. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,882
    Unless you are trying to change cameras a thousand times every Update(), none of these will have any impact on your game's performance. This is thinking backwards-- you should run the game, measure the game's performance in the profiler tools, find the thing that is holding your game back from performing well, and go fix that, IN THAT ORDER.
     
    Apeles likes this.
  14. Apeles

    Apeles

    Joined:
    May 16, 2022
    Posts:
    5
    Thank you very much for answer! I am relatively new to Unity, so this really helps... Best regards!