Search Unity

How to adjust speed based on behaviour parameters?

Discussion in 'Timeline' started by havchr, May 27, 2020.

  1. havchr

    havchr

    Joined:
    Jun 18, 2009
    Posts:
    75
    Hi - I am doing a score tally(countup) screen and using timeline to visualize the animations. What I am wanting - is to adjust the duration/speed of a clip/count-up , based on how much score there is. Is it possible to set the duration of a clip based on values from the Behaviour, or adjust the speed multiplier based on values from the behaviour?






    It would be awesome if it is possible - it's great to write UI animations and scrub them and see how they will look and use clips/etc to tweak timings.
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If you mean from a CustomEditor for your PlayableAsset (i.e. inspector), then yes. In your inspector you need to access the TimelineClip associated with your playable asset.

    TimelineEditor.selectedClip(s) is the property you want for the selected clip(s). You can change the values of the duration and timeScale fields in the clip to match.

    Some suggestions though to make this work well:
    • Cache the clip in OnEnable() to better support locked inspectors. Also, validate that targetObject = clip.asset to be safe (or to better support multiple selection).
    • When your target value changes in the inspector call Undo.RegisterCompleteObjectUndo(clip.parentTrack, "Your Undo Title"); before modifying the values to make them properly use the Undo/Redo system.
    • And after changing values call TimelineEditor.Refresh(RefreshReason.SceneNeedsRefresh); to get the values to display correctly. RefreshReason.ContentsModified seems like the more logical choice, but if you are only updating the timing of a clip, this is much faster.
    I hope that helps.
     
  3. havchr

    havchr

    Joined:
    Jun 18, 2009
    Posts:
    75
    Thanks - that was really helpful, and I did manage to adjust the clips based on values from the behavior. I did however, realize that what I really wanted to do - was this in the mixerBehaviour:

    Code (CSharp):
    1.  
    2. var speed = FromBehaviourCalculateSpeed(behaviour,inputWeight);
    3. playable.GetGraph().GetRootPlayable().SetSpeed(speed);
    4.  
    Which would let me slow down everything and then speed up again once I was done counting up a high score - leaving the rest of my animations and timings the same.
     
    seant_unity likes this.