Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Accessing Cinemachine.CinemachineBrain ActiveVirtualCamera, and CinemachineBlend

Discussion in 'Cinemachine' started by Craze74, Oct 11, 2019.

  1. Craze74

    Craze74

    Joined:
    Nov 19, 2012
    Posts:
    83
    Hello !

    I am trying to access the ActiveVirtualCamera described here : https://docs.unity3d.com/Packages/c...79.198086908.1570393819-1487674585.1568234350

    but I think I am not understanding correctly how I can use these informations.

    I am using this script :


    Code (CSharp):
    1. public class CameraLookTargetPivot : MonoBehaviour
    2. {
    3.  
    4.     public Cinemachine.CinemachineBrain camera;
    5.    
    6.     void Update()
    7.     {
    8.         if(camera.ActiveVirtualCamera == "MyVirtualCamera")
    9.         {
    10.  
    11.         }
    12.  
    13.         Debug.Log(camera.ActiveVirtualCamera);
    14.  
    15.     }
    The debug sends me the information of the current active camera correctly, but now I would like to use my if statement as 'If the camera with this name is used, then... '

    I understand the type of the value is not a string and therefore what I did using a string "MyVirtualCamera" won't work, but I don't understand how I can transform my name information into a type of CinemachineCamera as described in the documentation.




    My other worry is I am trying to access some values in the class 'CinemachineBlend', but I am definitely not using it correctly.

    I wanted to take my camera and do as follow :
    Code (CSharp):
    1. public class CameraLookTargetPivot : MonoBehaviour
    2. {
    3.  
    4.     public Cinemachine.CinemachineBlend camera;
    5.    
    6.     void Update()
    7.     {
    8.         if(camera.isComplete)
    9.         {
    10.  
    11.         }
    12.  
    13.     }
    But I can't plug my camera in the inspector using this declaration.

    Any ideas ?

    Thank you guys !
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    CinemachineBrain.ICinemachineCamera is an object of type ICinemachineCamera. If you look at the documentation for ICinemachineCamera, you'll see what you can do with it. One of the things you can do is get its name using its Name property, for example:
    if(camera.ActiveVirtualCamera.Name == "MyVirtualCamera")


    An object of type CinemachineBlend is not a camera, it's a blend. You can't ask a camera if it's complete, but you can ask a blend. Since a camera is not a blend, the UI won't let you drop your camera into a slot that's expecting a blend. What exactly are you trying to set up here?

    C# is a strongly-typed language. That means that the type of the object must be respected, and the system won't automatically convert one type to another. That's why you can't compare a camera to a string.

    Perhaps your coding background is centered around a different language with different rules. In that case, I would recommend that you invest a little time learning the basics of C#. There are many free online courses that will get you up to speed fairly quickly. Here is one: https://unity3d.com/learning-c-sharp-in-unity-for-beginners
     
    Last edited: Oct 15, 2019
  3. Craze74

    Craze74

    Joined:
    Nov 19, 2012
    Posts:
    83
    That makes total sense, thanks a lot !

    In the end for the CinemachineBlend, I was trying to get an access to the cinemachineComponent, and in the end I found that I could access them like so :

    Code (CSharp):
    1. public Cinemachine.CinemachineTransposer composer;
    2. composer = GetComponent<Cinemachine.CinemachineVirtualCamera>().GetCinemachineComponent<Cinemachine.CinemachineTransposer>();
    My background is mainly python directly in 3D application, so a bit confusing to switch to C#

    Thanks again !
     
    Gregoryl likes this.