Search Unity

Best way to find out if a virtual camera has fully transitioned?

Discussion in 'Cinemachine' started by Romano, Jun 23, 2019.

  1. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    Hiya! I was wondering what the best way to find out if a virtual camera has fully transitioned to another one is?
    I'm planning to set my camera active and then do something like this in a coroutine:
    Code (CSharp):
    1. while (cinemachineBrain.IsBlending)
    2. {
    3.     yield return null;
    4. }
    I don't know if there's any pitfalls in doing it this way or if there's a better way, so I'd appreciate anyone's advice on this.

    Thanks!

    Edit: My plan didn't seem to work...
     
    Last edited: Jun 23, 2019
    Alverik likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It should work. IsBlending will return false when the blend is finished.
     
  3. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    Hi! It didn't seem to kick in until after a couple of frames. I had to use this code to get it to work:

    Code (CSharp):
    1. IEnumerator ChangeCameraAfterBlendCoroutine()
    2.     {
    3.         cameraScript.ActivateCamera(10);
    4.         yield return null; yield return null;
    5.         while (cameraScript.cinemachine.IsBlending) { yield return null; }
    6.         cameraScript.ActivateCamera(8);
    7.     }
    (The ActivateCamera function is just setting the virtual camera object active and deactivating the others in the list)

    Is this still the best/ only way to wait for a blend to be finished or is there some other way? I checked the documentation but this was all I could find.

    Thanks!
     
    Last edited: Jun 23, 2019
    DavidZobrist likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    That's pretty much the way
     
    DavidZobrist likes this.
  5. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    Great thanks!
     
  6. TreseBrothers

    TreseBrothers

    Joined:
    Jan 14, 2016
    Posts:
    20
    Thanks, super helpful.
     
  7. RiDeV30

    RiDeV30

    Joined:
    Feb 23, 2022
    Posts:
    1
    another way

    Code (CSharp):
    1. private IEnumerator ChangeCameraAndDoSomething() {
    2.         ChangeCamera();
    3.  
    4.         // cause IsBlending has little bit delay so it's need to wait
    5.         yield return new WaitUntil(() => mainCamBrain.IsBlending);
    6.  
    7.         // wait until blending is finished
    8.         yield return new WaitUntil(() => !mainCamBrain.IsBlending);
    9.  
    10.         WhatToDoAfterFinished();
    11.     }
    mainCamBrain is your cinemachine brain usually on main camera,
    it's may not a best way but it's work