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

Find current active Vcam in scene

Discussion in 'Cinemachine' started by CaringKarol, Apr 12, 2020.

  1. CaringKarol

    CaringKarol

    Joined:
    Jan 22, 2018
    Posts:
    28
    Hi, I was wondering if there was a way to find an an active virtual camera in a scene when scripting. I have a script that's supposed to change the object that the virtual camera is following and the only problem I'm having is figuring out how to let the script know what camera it's supposed to be affecting.

    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    Indeed there is.
    Get the CM Brain (it's a component on your main camera) and access its ActiveVirtualCamera property.

    When you say "change the object that the virtual camera is following" do you mean that you want to change some property on the target object, or that you want to get the vcam to follow a new target? If the latter, then the correct way to do it is to activate a new vcam that follows the new target. The brain will take care of blending from the old vcam to the newly activated one. If you just set a new target on the same vcam, it will pop to the new position, not blend.
     
    kypronite likes this.
  3. CaringKarol

    CaringKarol

    Joined:
    Jan 22, 2018
    Posts:
    28
    Oh! Okay! Thank you so much!