Search Unity

Mecanim events firing incorectly when clip is playing in reverse? Bug?

Discussion in 'Animation' started by Foxxis, Feb 7, 2014.

  1. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Hi,

    I have a stair climbing animation which is firing some events. When playing it forwards it works as expected. However, reversing the clip with animator.speed = -1 will cause the events to fire seemingly nonstop at every curve position.
    Is there a known problem with events and reverse playback...?

    Many thanks in advance for any info!
     
  2. TH-Interactive

    TH-Interactive

    Joined:
    May 26, 2013
    Posts:
    34
    Hi all,
    I am also finding this issue - make animations play with speed of -1 and anim events fire every frame.
    Please fix Unity!
     
  3. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Please file a bug report for this and post the bug number. I did so back last year but it may have been purged since then. The more reports, the better.
     
  4. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    This bug has been fixed in 5.0
     
  5. TH-Interactive

    TH-Interactive

    Joined:
    May 26, 2013
    Posts:
    34
    Hi Mecanim.Dev,
    Is there any way this could be backported to 4.6? We've already spent thousands on Unity over it's different versions and another $750 for an essential bug fix seems a bit unreasonable...
     
  6. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Sorry I did misread, this bug is not yet fixed in 5.0 but we are working on fix.

    Depending on the size of the fix if it not too risky we will try to backport the fix to 4.6.
    We will post more information when the fix is ready.
     
  7. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    We did some investigation and it turn out that setting animator.speed to a negative value was never really supported.
    Transition are not updated correctly, animation events are not fired correctly and there is a lot more.

    Negative value only make sense when you record some data and then playback this data, in this case you can go backward since you have some pre baked data.

    So before we start to change anything I'm curious to know what is your use case exactly?
     
  8. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,347
    My use case would be ...
    say you swing a weapon (speed 1) you connect with target so you want to draw the weapon back now to reswing making the speed -1 is by far the easiest way to do this
     
  9. TH-Interactive

    TH-Interactive

    Joined:
    May 26, 2013
    Posts:
    34
    Thanks Mecanim, really hoping for a fix soon!
     
  10. TH-Interactive

    TH-Interactive

    Joined:
    May 26, 2013
    Posts:
    34
    Hi Mecanim.dev, didn't see the post earlier sorry.

    For us it can be used in many places - we are developing an fps.
    Most obvious use cases for us is climbing up/down a ladder, with events for when the hands should grab to rails.
    Another example is changing weapons for holstering/grabbing a weapon and events for when the weapon should be parented to the holster/hand grabbing it.
     
  11. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Being able to play animations backward correctly is indeed a much needed feature. We also play ladder climbing and a slew or other actions backwards. Since we are an indie studio and rely on third party mocap data (various libraries including but not limited to Mixamo), said mocap data is not always available in forwards+backwards variants, so being able to flip the animation speed in Unity is by far the quickest way to deal with this.
    Sure, we can flip it in our animation software, but if you would properly support negative playback speeds we would very much appreciate it.
     
  12. TH-Interactive

    TH-Interactive

    Joined:
    May 26, 2013
    Posts:
    34
    I just saw that in the latest beta negative speeds for Mecanim animations will be clamped to 0.
    Does this mean that Mecanim will never support playing animations backwards?
     
  13. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Seriously?
    Clamping the speed to minimun zero will have major impact on our project. Please reconsider, there is no reason to prohibit negative speeds.
     
  14. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    No, in 5.1 we did add a new feature that allow you to change speed of any animator state, this new feature does support backwards animation correctly and animation events are fired in the right order. You can still get the same behaviour than before just by setting all your animator state speed parameter to the same controller parameter.

    Animator.speed cannot be negative because there is to much issue that we cannot fix since it was never mean to be negative. And we think that this new feature in 5.1 will give you more flexibility with less issue in the long run
     
  15. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    There have been various terms used in the thread and I may have mixed things up as well. Just to be clear:
    We set the animator.speed to positive in all situations, but in the animator state inspector, we do have states with the Speed parameter set to negative values (to reuse a forward animation clip). This used to not properly support event firing etc.

    Do I understand you correctly if I interpret you as follows:
    - our practice as described above will now work properly, including fire events as intended
    - setting animator.speed will not work and will be clamped

    Thanks in advance!
     
  16. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Yes exactly, I did work the past two week to make sure that all combination of AnimatorState.speed and BlendTree's ChildMotion.timeScale yield the expected result for both the animation and animation events.
    If you have some test case that you know are failing right now I would be happy to check them with our latest modification to be sure that we cover all cases.


    right, animator.speed is now clamped at minimum zero
     
  17. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Perfect - sounds like exactly what we have been wanting for a while. :)
    We are still on 4.6.x, but if we run into problems after migrating (will happen soonish) I will definitely let you know. :)

    Thank you for the work and the info!
     
  18. TH-Interactive

    TH-Interactive

    Joined:
    May 26, 2013
    Posts:
    34
    Thanks guys yes that is the same situation we are in - Animator.speed is always 1 but the state itself needs to be able to play backwards and play events correctly too.

    Thanks for the clarification and great work, that's a big help for us!
     
  19. wuzibu

    wuzibu

    Joined:
    Dec 15, 2014
    Posts:
    10
    Thanks for this feature. We need this as well. Looking forward for the next release :)
     
  20. ratmat2002

    ratmat2002

    Joined:
    Jun 13, 2014
    Posts:
    35
    UPDATED:

    I'm using Unity 5.3.1 and when I set the speed of an animator state to -1 in the inspector, it seems to start the animation at the 1:00 mark (1 second, 0 frames) rather than at the end of the animation. When playing forward, the animation plays all the way to the end. I inserted AnimationEvents every 5 frames to confirm that when played in reverse, only those at mark 1:00 and below are fired. When playing forward, all AnimationEvents even those past the 1:00 mark are fired.
     
    Last edited: Jan 5, 2016
  21. JodySVS

    JodySVS

    Joined:
    Apr 29, 2015
    Posts:
    19
    Hi, Mecanim Dev! I am using a speed multiplier parameter on Unity 5.3.1 and this particular animation state goes back and forth with another animation state. Basically it's a right arm ladder climb and a left arm ladder climb (mirrored to save animation time). So when I have the multiplier more than 0 it transitions back and forth correctly, but when I set the multiplier negative, the transition doesn't happen and the animation repeats itself. However many times down I climb it seems to add up so that when I go positive again it has to glitch/repeat and not transition that many times before the transitions kick in and start working again. Thoughts?

    Update:
    Tried Unity 5.3.2 and have the save problem.
     
    Last edited: Feb 17, 2016
  22. Tekksin

    Tekksin

    Joined:
    Oct 20, 2013
    Posts:
    32
    if there are any noobs scowaring the internet like me because the animator clips aren't playing forwards and backwards based on the animation speed you set up in your script, just make sure to select the animation clip and apply the multiplier parameter in the inspector.

    My code is ridiculously clean now because of this, but I'm still not happy about an hour and a half of mystery.
     
unityunity