Search Unity

Animation won't play consistently

Discussion in 'Cinemachine' started by orenhod, Jun 14, 2019.

  1. orenhod

    orenhod

    Joined:
    Jun 6, 2016
    Posts:
    2
    Hi all, I have this problem that drives me nuts where repeatedly playing a chinemachine animation track repeatedly won't consistently play the animation.

    I have a simple scene that includes:
    - A cube object
    - Two virtual camera. "Virtual camera 1" is further away from the cube while "virtual camera 2" is closer.
    - A "forward" timeline animation that use a cinemachine track to move from virtual camera 1 to 2 (toward the cube).
    - A "backward" timeline animation that use a cinemachine track to move from virtual camera 2 back to 1 (away from the cube).

    With each click on the cube, I toggle between the animations. So first click moves the camera toward the cube, second click moves it backward, third click forward again, then backward, and so on and so on.

    The problem is that while the first two animations play well, starting from the third click, the forward animations won't play at all but the backward animations will.

    You can see the screen recording here:

    Note the debug log shows the animation should play but only the backward animations do...

    Scene and timeline:
    upload_2019-6-13_20-37-15.png

    Code:
    upload_2019-6-13_20-37-57.png

    Thanks for helping!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    The thing to remember is that a CM track in Timeline is really just a temporary activation track, valid only while the timeline is actually playing.

    The reason your approach isn't working is that the CM timeline clips only set the current vcam for as long as the clip is running. When the clip finishes playing, the vcam that it blended to stops being the current active vcam, and things revert to whatever vcam is active in the timeliene-less state.

    If all you're trying to do is activate one camera or another based on a game event, you don't need timeline at all. Your scripts only need to do something like this:
    Code (CSharp):
    1. void OnEvent()
    2. {
    3.     vcamOld.SetActive(false);
    4.     vcamNew.SetActive(true);
    5. }
    and you allow the brain to make the blend. You can set up custom blends in the brain to control the blend times of different vcam combinations, if you like.
     
  3. orenhod

    orenhod

    Joined:
    Jun 6, 2016
    Posts:
    2
    Thanks Gregoryl. I do want to show a transition (cutscene) to get the feeling that the user is moving across the screen.

    I have found that if I change the code to "p.Play(p.playableAsset)" instead of just p.Play() things work correctly.
     
    Gregoryl likes this.