Reverse animation in PlayAnimatorClip

Slate Forums General Discussion Reverse animation in PlayAnimatorClip

This topic contains 2 replies, has 2 voices, and was last updated by  Gavalakis 7 months, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #1583


    Today I needed to play an animation clip reversed to undo an effect and noticed that the PlayAnimatorClip clip didn’t have such functionality.
    So I did a quick implementation.

    Would be great if you could consider adding it in a future update.

    In the PlayAnimatorClip class, I added a field

    [HelpBox("Set to make the animation clip play in the reverse direction.")]
    private bool _playReverse;

    Then, on the OnUpdate method, I did the following change

    protected override void OnUpdate(float time, float previousTime){
    	if (track.useRootMotion && steerLocalRotation != default(Vector2)){
    		var rot = wasRotation + (Vector3)steerLocalRotation;
    	var scaledTime = (time - clipOffset) * playbackSpeed;
    	var scaledPreviousTime = (previousTime - clipOffset) * playbackSpeed;
    	if (_playReverse) {
    		scaledTime = animationClip.length - scaledTime;
    		scaledPreviousTime = animationClip.length - scaledPreviousTime;
    	track.UpdateClip(this, scaledTime, scaledPreviousTime, GetClipWeight(time) );

    All the best!



    I also needed this feature and did a pretty much identical implementation.
    Would be nice to have it included officially, this is very useful.

    Searching around the net, I can see people requesting a way to do this for a long time. It’s still not possible to have it with the latest Unity timeline. Having access to the source and being able to change it quickly is fundamental.




    Thanks for the heads up.
    An easier way, would be to simply allow a negative playback speed by changing the Range attribute to something like [Range(-5, 5] 😀 (which is something I just did by the way).


Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.