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

Changing Cinemachine default blend time at runtime

Discussion in 'Cinemachine' started by Flag74, Nov 12, 2018.

  1. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    On my cinemachine brain I have a standard EaseInOut default blend.LateUpdate mode.
    If I set:
    Code (CSharp):
    1. cinemachineBrain.m_DefaultBlend.m_Time = time;
    and then setting another vCam to higher priority, it just starts a new Blend using *previous* blend time.
    It seems that this value is being used/updated on the next update only?
    What should I do to set my blend time and make brain use it immediately for the next blend?

    thx
     
  2. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    Can't believe I had to do this to make it work...that's so bad...

    Code (CSharp):
    1.         cinemachineBrain.enabled = false;
    2.         cinemachineBrain.m_DefaultBlend.m_Time = time;
    3.         cinemachineBrain.enabled = true;
    4.  
     
    bstockwell likes this.
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    That's very strange. There is no reason for that to be necessary. I just tried it myself with the following script; it works perfectly. What are you doing that's different?

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class Switcheroo : MonoBehaviour
    5. {
    6.     public CinemachineVirtualCamera vcam1;
    7.     public CinemachineVirtualCamera vcam2;
    8.     public float time = 1;
    9.     public bool switchNow;
    10.  
    11.     void Update ()
    12.     {
    13.         if (switchNow)
    14.         {
    15.             var brain = GetComponent<CinemachineBrain>();
    16.             brain.m_DefaultBlend.m_Time = time;
    17.             if (brain.IsLive(vcam1))
    18.             {
    19.                 vcam1.Priority = 9;
    20.                 vcam2.Priority = 10;
    21.             }
    22.             else
    23.             {
    24.                 vcam1.Priority = 10;
    25.                 vcam2.Priority = 9;
    26.             }
    27.             switchNow = false;
    28.         }
    29.     }
    30. }
    31.  
     
    CrossAngeluS likes this.
  4. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    Maybe the difference is that the previous vcam gets deactivated after the new one got priority set ?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    The order in which you set the priorities makes no difference, nobody looks at them until Brain does its LateUpdate, at which time everything is processed at once.
     
  6. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    No, I mean that the GameObject that contains the old vCam gets deactivated.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    You mean like this?
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class Switcheroo : MonoBehaviour
    5. {
    6.     public CinemachineVirtualCamera vcam1;
    7.     public CinemachineVirtualCamera vcam2;
    8.     public float time = 1;
    9.     public bool switchNow;
    10.  
    11.     void Update ()
    12.     {
    13.         if (switchNow)
    14.         {
    15.             var brain = GetComponent<CinemachineBrain>();
    16.             brain.m_DefaultBlend.m_Time = time;
    17.             if (brain.IsLive(vcam1))
    18.             {
    19.                 vcam2.gameObject.SetActive(true);
    20.                 vcam1.gameObject.SetActive(false);
    21.             }
    22.             else
    23.             {
    24.                 vcam2.gameObject.SetActive(false);
    25.                 vcam1.gameObject.SetActive(true);
    26.             }
    27.             switchNow = false;
    28.         }
    29.     }
    30. }
    31.  
    32.  
    Still works for me.
     
    mishakozlov74 likes this.