Search Unity

Blend from Timeline Cinemachine Track to CinemachineVirtualCamera Priority

Discussion in 'Cinemachine' started by Xarbrough, Jun 30, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I'm having some trouble setting up a nice workflow to handle the following situation:
    • I have a series of levels, each level has a fixed CinemachineVirtualCamera, all have the same priority
    • In some levels, a Timeline takes over the control over the current camera and blends between specific configurations or simply animates the level camera
    • The game needs to be able to start at each level
    I now run into the following issue: I have two cameras A and B. Both have the same priority, but by default camera A is on top of the current priority queue. I now animate a Timeline blending from A to B. At the end of the timeline the camera is at position B. Now my gameplay code takes over and sets the level B camera to the top of the priority queue which causes the CinemachineBrain to animate a blending from A to B, although I'm already at position B. This is want to avoid.

    If I remove the priority queue setting in my gameplay code, I can't start the game at level B, because level A is currently still loaded and receives a higher camera priority. So instead I set the priority at level start of B, but then it messes with the blending.

    Can anyone give me tips on how to handle this situation?

    What I actually want would be something like this:
    • I can control cameras via timeline
    • When timeline is not running (stops playing), nothing happens to the current camera setup
    • I can explicitly trigger a blend to a different vcam in code
    I think the last point is at the heart of the problem: Can I not disable the default priority blending and instead explicitly call a transition request which blends form the current (real Unity) camera to specified vcam? In this case I kind of want to discard all previous vcams and only blend from the actual camera position to a new vcam.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    The way the timeline works is to act as an override for the priority system. The override only has effect while the timeline is playing, and when the timeline stops, the override disappears along with it, and the priority system takes over once again.

    Because the timeline completely overrides the priority system while it is playing, you can take that opportunity to set up for the next level. Deactivate vcam A and activate vcam B while the timeline is playing. When the timeline stops, it will stay on vcam B.

    Note that the timeline override is very powerful: it will even force-play a deactivated vcam, so you should have no fear about deactivating vcam A while timeline is playing, or of allowing timeline to blend into deactivated vcam B.

    To explicitly trigger a blend to a new vcam in code, just deactivate the outgoing vcam and activate the incoming one. Or leave them both activated and give the incoming one a higher priority, or the outgoing one a lower priority. You can do all that in the same frame. The blend system, like timeline, can work with deactivated vcams.

    I hope that answers your questions. If not, please feel free to ask more.

    EDIT: there's yet another way. You can add an animation track in the timeline to animate the vcam priorities, so when the timeline finishes all the vcams have the right priority.
     
    Last edited: Jun 30, 2019
    LiterallyJeff likes this.
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    @Gregoryl: Thanks! I've tried your suggestions and it clarified a lot about how Cinemachine works with Timeline. Activating and deactivating the cameras in Timeline actually worked nicely, but I still experimented a litte in hopes for a solution that requires less manual setup.

    My current solution actually uses another option: All of my virtual cameras call MoveToTopOfPrioritySubQueue during their OnCameraLive event. This ensures that when a timeline plays and finishes, its last animated vcam has highest priority and therefore, when blending to the next camera via code, it works. In this case all cameras have the same priority. I think in my case this saves me some of the manual setup. I'll keep an eye on performance and see if this is actually better than manually activating and deactivating individual cameras, but so far it was working nicely.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Brilliant! Excellent and simple solution.