banner



Ui Animations Ue4 Not Playing to Finish

Search Unity

Unity ID

A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate in the Unity community.

  1. I've added an animation to my timeline, but the timescale on that animation won't let me specify a negative number. How can I play the animation in reverse? (Speed -1).
  2. Hi,
    Unfortunately, right now there is no way to play an animation in reverse inside timeline. It's something that came up a couple of time but there is no easy way to do it. Only solution I can give you is to duplicate your clip and inside the animation window, using the box tool, you could reverse the 2nd clip.
  3. Ah damn, that's really disappointing!

    Thanks for your answer.

  4. could you please explain how to do it? What's a box tool?
  5. What about this?
    https://docs.unity3d.com/ScriptReference/Playables.PlayableDirector.Evaluate.html

    I this it should allow you to play it backwards from the coroutine or update.

  6. Timeline can't currently play animations backwards.

    To fix this, you can duplicate your animation in the project window, and then create a reversed copy in "Keys" view by dragging right to its end then scaling negatively, which works, but is a pain on large animations as the Animation UI becomes quite unresponsive.

    Or, you can clone your anim and run this script:

    https://answers.unity.com/questions/476819/reverse-animation-help.html

    Both confirmed working in 2017.4, but the script version is much less hassle.

    It would be nice to be able to create the reversed animation clip at runtime, but I believe that's not possible until 2018.2 (?)

  7. If it helps anyone else, I modified the script above to be inside the context menu when you right click on an animation clip. It also automatically creates the copy and adds "_Reversed" to the name so you don't have to copy it first. Not perfect, but it saves me some time.

    1. public static class ReverseAnimationContext
    2. [MenuItem( "Assets/Create Reversed Clip", false, 14 ) ]
    3. private static void ReverseClip( )
    4. string directoryPath = Path. GetDirectoryName (AssetDatabase. GetAssetPath (Selection. activeObject ) ) ;
    5. string fileName = Path. GetFileName (AssetDatabase. GetAssetPath (Selection. activeObject ) ) ;
    6. string fileExtension = Path. GetExtension (AssetDatabase. GetAssetPath (Selection. activeObject ) ) ;
    7.         fileName = fileName. Split ( '.' ) [ 0 ] ;
    8. string copiedFilePath = directoryPath + Path. DirectorySeparatorChar + fileName + "_Reversed" + fileExtension;
    9. var clip = GetSelectedClip( ) ;
    10.         AssetDatabase. CopyAsset (AssetDatabase. GetAssetPath (Selection. activeObject ), copiedFilePath) ;
    11.         clip= (AnimationClip)AssetDatabase. LoadAssetAtPath (copiedFilePath, typeof (AnimationClip) ) ;
    12. float clipLength = clip. length ;
    13. var curves = AnimationUtility. GetAllCurves (clip, true ) ;
    14. foreach (AnimationClipCurveData curve in curves)
    15. var keys = curve. curve . keys ;
    16. int keyCount = keys. Length ;
    17. var postWrapmode = curve. curve . postWrapMode ;
    18.             curve. curve . postWrapMode = curve. curve . preWrapMode ;
    19.             curve. curve . preWrapMode = postWrapmode;
    20. for ( int i = 0 ; i < keyCount; i++ )
    21.                 K. time = clipLength - K. time ;
    22.                 K. inTangent = -K. outTangent ;
    23.             clip. SetCurve (curve. path, curve. type, curve. propertyName, curve. curve ) ;
    24. var events = AnimationUtility. GetAnimationEvents (clip) ;
    25. for ( int i = 0 ; i < events. Length ; i++ )
    26.                 events[i] . time = clipLength - events[i] . time ;
    27.             AnimationUtility. SetAnimationEvents (clip, events) ;
    28.         Debug. Log ( "Animation reversed!" ) ;
    29. [MenuItem( "Assets/Create Reversed Clip", true ) ]
    30. static bool ReverseClipValidation( )
    31. return Selection. activeObject . GetType ( ) == typeof (AnimationClip) ;
    32. public static AnimationClip GetSelectedClip( )
    33. var clips = Selection. GetFiltered ( typeof (AnimationClip), SelectionMode. Assets ) ;
    34. return clips[ 0 ] as AnimationClip;
  8. xhdfgT

    xhdfgT

    Joined:
    Feb 12, 2017
    Posts:
    1
    Your Script is Amazing, it is working fine, Thanks for sharing
  9. Such a useful function. This should be in unity by default, if there is no easy way to reverse a clip in Timeline.
  10. @Straafe You could change the menu path to "CONTEXT/AnimationClip/Create Reversed Clip" to make it a context menu function on the AnimationClip asset instead. Give it a "MenuCommand command" parameter and use "command.context" to access the clip it's being called on instead of "Selection.activeObject". That way you could select multiple clips and run the function for all of them at once (and it isn't taking up space in the main Assets menu).
    fbittner and ferretnt like this.
  11. @Straafe You are so amazing!! Thank you so much. Can I post your code on my blog? Of course, I'll write where it came from and who wrote it. Thank you!
  12. Sure, please do. @pinaeong
  13. sorry but where exactly do i place this code? thanks
  14. Thank you @Straafe for this script !!!!

    (@steveh2112 : put it into an folder named Editor, also make sure that the file is named ReverseAnimationContext.cs )

  15. In this video the man change the speed to negative and the animation starts playing backwards

  16. @Straafe and @Bunny83
    Unity 2019 has updated a few things which changed what this generates. Can you provide an update?

    Unity gives me the warning:
    Assets\Editor\ReverseAnimationContext.cs(25,22): warning CS0618: 'AnimationUtility.GetAllCurves(AnimationClip, bool)' is obsolete: 'GetAllCurves is deprecated. Use GetCurveBindings and GetObjectReferenceCurveBindings instead.'

  17. Hi @BellBlitzKing ,

    I updated the script above to use the newer functions and no longer use the deprecated one. It also now supports multiple animation clips at a time, so you can shift-click or ctrl-click multiple clips and reverse them all at once.

    You can find it here (haven't done much testing, so let me know if there's a problem):
    https://github.com/Straafe/unity-editor-tools/blob/master/ReverseAnimationContext.cs

    I also added a couple more scripts there, one to add a default empty state to an AnimationController and one to unloop AnimationClips which default to looped most of the time. Both of those also support multi select and have helped me a lot in some situations. Still not perfect, but it works.

    https://github.com/Straafe/unity-editor-tools

    @Kybernetik I got it to work with multiple clips at once, but please improve it!

    Last edited: Apr 27, 2020
  18. Thank you @Straafe ! Get it while it's fresh, @Elin42 @rudehouse , @pinaeong , @thierry_unity , @vladk ,

    ReverseAnimationContext.cs allows you to easily reverse animation clips:

  19. Thank you @Straafe, this is really amazing, unity should integrate this feature by default. You saved us a lot of time.
  20. @Straafe you are amazing thank you so much. You saved my day
  21. Hi.
    At the moment it does not seem to work with sprites, but it still helped me with my animated colliders etc.

    would it be possible to have this work for sprites as well?

    Anyway still Thanks @Straafe as it saved me hand setting collider animations :)

  22. Hi @Djaydino , I almost exclusively work with 3D models and 3D scenes, so I haven't done much in 2D with sprite or sprite animations. Do they still use Animation Clips? In theory it should work with anything that uses clips.
  23. Hi.
    Thank for your reply.

    Yes they are within the clip and on a older version i copied from here they where disappeared after reversed.
    Then i tried with the github version and with this version they do not disappear, but they are also not reversing.

    But i think it is probably not possible.
    If you select a clip directly from project then you are not able to add sprites, only move/remove.

  24. @Straafe Please tell me how I should attribute you since I want to use this in production. At the moment, I want to provide your user handle and the link to this post on the top of the code.

    My only complaint is that `AnimationUtility.GetAllCurves` is deprecated now.

  25. @Vivraan Hey, that sounds perfectly fine to me. I believe I updated it to not use the deprecated functions here: https://github.com/Straafe/unity-editor-tools/blob/master/ReverseAnimationContext.cs
  26. Alright, so I modified the script to be a bit more "modern" (if at the lack of compatibility) and replaced the
                              GetAllCurves                        
    method with the editor bindings API.

    @Straafe could you comment on the shortcomings of this edit I made?

    (See below for updated script.)

    Last edited: Sep 28, 2020
  27. Really like the multiple clips reversal context, although I believe just reversing one at a time would suffice! (We seriously need our animators to make reversed versions since this isn't Godot :p)
  28. The corrected version is:
    1. /// Originally from Straafe
    2. /// From https://forum.unity.com/threads/how-can-i-play-an-animation-backwards.498287/#post-5004851
    3. public static class ReverseAnimationContext
    4. [MenuItem( "Assets/Create Reversed Clip", false, 14 ) ]
    5. private static void ReverseClip( )
    6. string path = AssetDatabase. GetAssetPath (Selection. activeObject ) ;
    7. string directoryPath = Path. GetDirectoryName (path) ;
    8. string fileName = Path. GetFileName (path) . Split ( '.' ) [ 0 ] ;
    9. string fileExtension = Path. GetExtension (path) ;
    10. string copiedFilePath = Path. Combine (directoryPath, $"{fileName}_Reversed{fileExtension}" ) ;
    11.             AssetDatabase. CopyAsset (path, copiedFilePath) ;
    12. var clip = AssetDatabase. LoadAssetAtPath <AnimationClip> (copiedFilePath) ;
    13. float clipLength = clip. length ;
    14. var editorBindings = AnimationUtility. GetCurveBindings (clip) ;
    15. foreach ( var binding in editorBindings)
    16. var curve = AnimationUtility. GetEditorCurve (clip, binding) ;
    17. var postWrapmode = curve. postWrapMode ;
    18.                 curve. postWrapMode = curve. preWrapMode ;
    19.                 curve. preWrapMode = postWrapmode;
    20. for ( int i = 0 ; i < keys. Length ; i++ )
    21.                     K. time = clipLength - K. time ;
    22.                     K. inTangent = -K. outTangent ;
    23.                 clip. SetCurve (binding. path, binding. type, binding. propertyName, curve) ;
    24. var events = AnimationUtility. GetAnimationEvents (clip) ;
    25. foreach ( var @event in events)
    26.                 @event . time = clipLength - @event . time ;
    27.             AnimationUtility. SetAnimationEvents (clip, events) ;
    28.             Debug. Log ( "Animation reversed!" ) ;
    29. [MenuItem( "Assets/Create Reversed Clip", true ) ]
    30. private static bool ReverseClipValidation( ) => Selection. activeObject is AnimationClip;
    31. private static AnimationClip SelectedClip => Selection. GetFiltered <AnimationClip> (SelectionMode. Assets ) . FirstOrDefault ( ) ;
  29. Hi everyone!

    in Unity (until 2020) I just typed:
    animator.speed = -1f;

    in Unity 2020 (and above) I need to enter:
    animator.StartPlayback ();
    animator.speed = -1f;

    It works for me!!!

  30. I agree, negative speed has worked for some time now??
  31. SiWoC

    SiWoC

    Joined:
    Feb 16, 2021
    Posts:
    6
    animator.speed = -1f;

    gives me

    Animator.speed can only be negative when Animator recorder is enabled. Animator.recorderMode != AnimatorRecorderMode.Offline

  32. Are you setting the speed on the state or the whole animator?
  33. SiWoC

    SiWoC

    Joined:
    Feb 16, 2021
    Posts:
    6
    Of the animator (GetComponent<Animator>())

    Property or indexer 'AnimatorStateInfo.speed' cannot be assigned to -- it is read only

    Why are you suggesting this?
    Do you know another way through "state"? Which state do you mean?
    Do you have code showing this?

  34. In the animator statemachine, select the state and in the inspector set the speed to -ve. I.e. each state plays its animation at a specific speed.
  35. Thanks so much for the script I would have sat there for days without it
  36. sylvin

    sylvin

    Joined:
    Apr 26, 2021
    Posts:
    2
    No need for a new script, Just copy and paste the Animation state that you want to reverse on the Animator Window, then rename it and set the speed ( -1 for reverse). After that, you just need to call the animation by the new name in animator
  37. sylvin

    sylvin

    Joined:
    Apr 26, 2021
    Posts:
    2
    Just copy and paste the Animation state that you want to reverse on the Animator Window, then rename it and set the speed ( -1 for reverse). After that, you just need to call the animation by the new name in the animator
  38. @Straafe I'm using your script, and thanks a lot for that, very useful, but when I have a animation with Sprite property and it doesn't reverse the Sprite property, the sprite property doesn't have a curve. I'm missing something here?
  39. @brunobiluca @Djaydino Hey Bruno, I edited the script to include a loop that should account for sprites which use ObjectReferenceKeyframes instead of KeyFrames, so it should reverse sprite animations now. https://github.com/Straafe/unity-editor-tools/blob/master/ReverseAnimationContext.cs

    I don't use sprites often but noticed on the sprite I was testing with that the created clip displayed the incorrect time range and was only displaying the last key in the new animation clip, but you can get around that by double clicking on the key and it seems to properly reevaluate the length. It also appeared offset by 1 frame's worth of time in my test case. Let me know if you have any issues with it.

  40. Ana_22

    Ana_22

    Joined:
    Jul 29, 2019
    Posts:
    4
    @Straafe thank you! Works great ! I wish would work within the fbx file as well instead of extracted clips only. Not sure if that's possible. There's multiple benefits keeping the clip within the fbx.
  41. this is so helpful and time saving, water damage ceiling michigan thank you very much guys.
    Last edited: Nov 15, 2021

Ui Animations Ue4 Not Playing to Finish

Source: https://forum.unity.com/threads/how-can-i-play-an-animation-backwards.498287/

0 Response to "Ui Animations Ue4 Not Playing to Finish"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel