Search Unity

Question Virtual Camera blend not working after 'sceneLoaded' event

Discussion in 'Cinemachine' started by QNimbus, May 23, 2023.

  1. QNimbus

    QNimbus

    Joined:
    Apr 24, 2023
    Posts:
    1
    Hello all,

    I'm trying to create a camera blend immediately after my scene is loaded by updating the priority of my vCams. The only way I can get the blend to work is when I use Invoke() to add an artificial delay before changing the vCam priorities - without this the Cinemachine camera immediately switches to the 'new' camera without using the blend.

    Code (CSharp):
    1. public class LevelManager : MonoBehaviour {
    2.  
    3.     [SerializeField] CinemachineVirtualCamera worldVirtualCamera;
    4.     [SerializeField] CinemachineVirtualCamera playerVirtualCamera;
    5.  
    6.     void Awake() {
    7.         if (worldVirtualCamera && playerVirtualCamera) {
    8.             playerVirtualCamera.Priority = 1;
    9.             worldVirtualCamera.Priority = 2;
    10.         }
    11.     }
    12.  
    13.     void OnEnable() {
    14.         SceneManager.sceneLoaded += OnLevelLoaded;
    15.     }
    16.  
    17.     void OnDisable() {    
    18.         SceneManager.sceneLoaded -= OnLevelLoaded;
    19.     }
    20.  
    21.     void OnLevelLoaded(Scene scene, LoadSceneMode mode)
    22.     {
    23.         // Invoke("FollowPlayerCamera", 1f); // If I use this, the blend is executed
    24.         FollowPlayerCamera(); // If I use this, there is no blend
    25.     }
    26.  
    27.     void FollowPlayerCamera()
    28.     {
    29.         if (worldVirtualCamera && playerVirtualCamera)
    30.         {
    31.             playerVirtualCamera.Priority = worldVirtualCamera.Priority + 1;
    32.         }
    33.     }
    34. }
    upload_2023-5-23_12-20-42.png

    Please be gentle - I am new to the community and not that experienced at Unity (yet) :) Thanks for your help!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Is the CM Brain included in the scene that's loaded, or is it outside the scene?