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

Transition back to previous active vcam when stopping Cinemachine in Timeline

Discussion in 'Timeline' started by BennyKokMusic, Aug 11, 2020.

  1. BennyKokMusic

    BennyKokMusic

    Joined:
    Dec 22, 2016
    Posts:
    33
    So, I'm having a base CinemachineFreeLook cam as the character camera, and playing a timeline on awake, I can get it transitioned nicely to the Cinemachine clip in the timeline from the base cam, but if I wanted to stop the timeline from playing depending on the current situation in-game, it will jump-cut back to the base cam instead of a transition.

    Here's a gif for better visualization
    https://gyazo.com/c7860cf0ceed67fe779d613a5cced438
    In the gif, I'm pressing "a" to stop the timeline around the cam blends in the timeline

    Code (CSharp):
    1. public class Test : MonoBehaviour
    2. {
    3.     public PlayableDirector d;
    4.  
    5.     void Update()
    6.     {
    7.         if (Input.GetKey("a"))
    8.         {
    9.             d.Stop();
    10.         }
    11.     }
    12. }
    13.  
    Is there any way of dealing with this kind of situation. If possible, doing manual transition in code when stopping the timeline.

    I looked up the forum and saw that CM used
    SetCameraOverride
    for overriding the default behavior of CM for Timeline, so is it that
    ReleaseCameraOverride
    will ignore the transition somehow?

    Thanks in advance!

    [Edit] was intended to post in CM forum, since its more CM related, but accidentally posted here.
     
    Last edited: Aug 11, 2020
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    While the timeline is active and overriding the current virtual camera, the priority system is still active under the hood. Maybe you can try something like this: when you want to stop the timeline, get the current active camera from the brain (it will be the current timeline override vcam) and boost its priority so that it's higher than the normal vcam. Then stop the timeline. Next frame, lower the priority of that vcam again, and it will blend back to the normal vcam.
     
  3. BennyKokMusic

    BennyKokMusic

    Joined:
    Dec 22, 2016
    Posts:
    33
    Thanks for the suggestion, just tried to raise the priority of active vcam upon key press but seems it still jump back to the default camera upon stopping the director,

    so I tried a bit hacky way by trigging RaiseCameraPriority below via signal before the transition in timeline happens, and it kinda works...

    // This is the result of stopping during blends
    https://gyazo.com/2ba9bc0ac7cfc99caa38de858186c329

    // This is the result of stopping after vcam fully transited
    https://gyazo.com/2ba9bc0ac7cfc99caa38de858186c329

    Code (CSharp):
    1.     private ICinemachineCamera timelineVCam;
    2.     private int timelineVCamPriorityCache;
    3.  
    4.     void Update()
    5.     {
    6.         if (Input.GetKeyDown("a"))
    7.         {
    8.             d.Stop();
    9.             //restore the previous priority
    10.             timelineVCam.Priority = timelineVCamPriorityCache;
    11.         }
    12.     }
    13.  
    14.     public void RaiseCameraPriority()
    15.     {
    16.         timelineVCam = brain.ActiveVirtualCamera;
    17.         //cache the previous priority
    18.         timelineVCamPriorityCache = timelineVCam.Priority;
    19.         timelineVCam.Priority += 40;
    20.     }
     
    Last edited: Aug 11, 2020
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Yes, that idea won't work if the timeline stops during a transition.

    Here is another idea:
    Make a second timeline, this one with only a single CM track with a clip for the default vcam blending in:

    upload_2020-8-12_6-23-39.png

    When you want to stop your timeline, start this one, wait for the duration of the blend, then stop both of them.
     
    BennyKokMusic likes this.