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

How to finish cinemachinebrain's active blends? (by code)

Discussion in 'Cinemachine' started by FeastSC2, Apr 5, 2022.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    During cinemachine blends, the position of the main camera (the camera with the CinemachineBrain component) is moved towards a new destination.

    How can I accelerate/finish the blend of that main camera by code? So that the cinemachine brain goes immediately to its destination position.

    Caveats:
    I would like to not change the m_DefaultBlend's value on the CinemachineBrain.
    I simply want to accelerate the process of the active blends all the way to the end with a call in a script.

    Something along the lines of CinemachineBrain.DoJumpCut() or CinemachineBrain.FinishActiveBlends() or CinemachineBrain.SimulateBlends(float elapsedTime)
     
    Last edited: Apr 7, 2022
  2. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    Anybody knows how to do this?
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Hmmm, this isn't something that's come up before. What happens if you disable then enable the CMBrain?
     
    FeastSC2 likes this.
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    It seems like that works! ;D. Interesting.
    Code (CSharp):
    1.     public static void FinishActiveBlends(CinemachineBrain _brain)
    2.     {
    3.         _brain.enabled = false;
    4.         _brain.enabled = true;
    5.     }

    It would be nice to have control over the simulation of the blend.
    Something similar to Unity's particle system. They have a ParticleSystem.Simulate function.
     
    Last edited: Apr 7, 2022
    Gregoryl likes this.
  5. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    @Gregoryl I just realized that this doesn't work for some types of blending.

    For example in the case of a framing transposer's damping blending.

    I tried this:

    Code (CSharp):
    1.             c.gameObject.SetActive(false);
    2.             c.FramingTransposer.m_CenterOnActivate = true;
    3.             c.gameObject.SetActive(true);
    But it does not work for my use case because I am modifying the camera distance value, and the CenterOnActivate only affects whether the target is centered or not.
    In other words, if the camera distance is still being modified due to a blend, it is not blended to finition.

    What can I do to finish a camera distance type of blending on a framing transposer?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    In this case it is not blending, it is damping from its previous state.
    Try setting vcam.PreviousStateIsValid = false.