Search Unity

Question Cinemachine Overlapping Blends problem.

Discussion in 'Cinemachine' started by Xesk, Nov 7, 2022.

  1. Xesk

    Xesk

    Joined:
    Dec 26, 2017
    Posts:
    15
    I'm sorry, I'm not sure about the title of this problem.

    I'm trying to implement a "zoom camera". When I press a button, this camera is activated by setting a higher camera.priority, and when the button is released, we go back to the camera we had before, by lowering its priority again.

    The problem comes when pressing, releasing, and pressing the button again before the first blend has finished.


    In th video you can see it first doing a complete zoom in and a complete zoom out.
    Then IN-OUT-IN in a fast sequence, and OUT-IN-OUT in a fast sequence. See in these cases how the blend time is ignored and the camera transitions significantly faster to the destination camera.

    Here is the Activation/Deactivation Code Im using
    Code (CSharp):
    1.  
    2. [SerializeField] private CinemachineVirtualCamera zoomCamera;
    3.  
    4. public void ActivateZoomCamera()
    5. {
    6.     Debug.LogWarning("ZOOM IN");
    7.     zoomCamera.Priority = 30;
    8. }
    9.  
    10. public void DeactivateZoomCamera()
    11. {
    12.     Debug.LogWarning("ZOOM OUT");
    13.     zoomCamera.Priority = 0;
    14. }
    15.  
    By looking at internal Cinemachine code, I imagine that it has something to do that we are sending a blend event(cam1, cam2) two times, with cam1 and cam2 being the same reference, cinemachine detects that we have a blend running between those two, and tries to get the state (Duration, TimeInBlend) of that blend and work it from there...

    I've searched for solutions like [this one], but simply cutting the transition would not work for me, since I want a smooth transition independently on what state the blend is.

    I have tried implementing the solution in [this post], but I'm not sure how and why it works.
    I'm calling the function that the user has shared right before setting the priority.
    Depending on which value is passed by parameter, the next blend is smooth, but, from my experiments, the value has to be greater then the Duration of the previous blend in order to work correctly.
    If the value is lower, it makes no difference.
    This would be enough if it weren't that in our project we might have Custom Blends with longer or shorter durations, so I cannot pass a fixed value everytime...

    So, can anybody explain to me how the previous function works? Is there any solution to this problem that I''m not seeing? Am I in the correct path?

    Using Cinemachine Version 2.8.4, updated from December 20, 2021
     
    Last edited: Nov 7, 2022
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    This is was fixed in a later version, try updating Cinemachine to 2.8.9.
     
  3. Xesk

    Xesk

    Joined:
    Dec 26, 2017
    Posts:
    15
    Indeed!
    Updated to the latest version and it works perfectly.

    Thank you for the quick answer
     
    gaborkb likes this.