Search Unity

Cinemachine GenerateCameraActivationEvent doesnt change camera

Discussion in 'Cinemachine' started by Censureret, Sep 24, 2020.

  1. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    i have the following code:

    Code (CSharp):
    1.     public CinemachineVirtualCameraBase FreeFormCamera;
    2.     public CinemachineVirtualCameraBase TargetingCamera;
    3.     public CinemachineVirtualCameraBase AimCamera;
    4.  
    5.     public MotionController PlayerMotionController;
    6.     public Combatant PlayerCombatant;
    7.  
    8.     public CinemachineBrain Brain;
    9.  
    10.     public CinemachineVirtualCameraBase ActiveCamera;
    11.  
    12.  
    13.     private void Start()
    14.     {
    15.         ActiveCamera = FreeFormCamera;
    16.         ActiveCamera.Priority = 1;
    17.         TargetingCamera.Priority = 0;
    18.         AimCamera.Priority = 0;
    19.         CinemachineCore.Instance.GenerateCameraActivationEvent(ActiveCamera, null);
    20.     }
    21.  
    22.  
    23.     private void Update()
    24.     {
    25.         if (PlayerCombatant.IsTargetLocked)
    26.         {
    27.             ChangeCamera(TargetingCamera);
    28.         }
    29.         else
    30.         {
    31.             ChangeCamera(FreeFormCamera);
    32.         }
    33.     }
    34.  
    35.  
    36.     private void ChangeCamera(CinemachineVirtualCameraBase camera)
    37.     {
    38.         if (ActiveCamera != camera)
    39.         {
    40.             CinemachineCore.Instance.GenerateCameraActivationEvent(camera, ActiveCamera);
    41.             ActiveCamera = camera;
    42.         }
    43.     }
    44. }
    When i run the GenerateCameraActivationEvent nothing happens and the camera doesn't change.

    Can anyone see what I've done wrong?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    That's not how you activate virtual cameras. The event is generated by a vcam becoming activated, not the other way around.

    Activate a virtual camera by raising its priority or by activating its game object.
     
  3. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    Thank you for your quick response. How does this work with the blends i have?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    When a new vcam is activated (or prioritized), the CM Brain will blend from the outgoing vcam according to the default blend defined within the brain, or the custom blend settings, if one applies to the transition.

    upload_2020-9-23_19-50-18.png
     
    Censureret likes this.
  5. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    363
    This worked thank you a lot!