Search Unity

Bug AnimationClipPlayable.SetTime(0.0) fires animation events

Discussion in 'Animation' started by ShadyMike, Dec 3, 2021.

  1. ShadyMike

    ShadyMike

    Joined:
    Apr 14, 2013
    Posts:
    60
    Code (CSharp):
    1. AnimationClipPlayable.SetTime(0.0)
    This function fires two animation events that it should not be firing. I call this function to prepare for another playback after the animation has finished playing. The animation events fire twice for some reason, and I suspect it's because of this function call.

    Commenting out this function leads to only being able to play the animation once, but the events also fire only once (expected behaviour). With this line, I can play the animation as often as I please, but at the very start of the animation, the animation events are fired, in addition to their regular timings.

    Any clue how to fix this, or temporarily disable animation events from firing?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It also applies root motion between the old and new time, which is sometimes desirable.

    If you don't want that, just call SetTime twice in a row.
     
  3. ShadyMike

    ShadyMike

    Joined:
    Apr 14, 2013
    Posts:
    60
    Thank you, it works like expected now. I don't understand why but at least it works.

    Doesn't this look odd?
    Code (CSharp):
    1.         playableGraph.Attack.pAttacks[0].SetTime(0.0);
    2.         playableGraph.Attack.pAttacks[0].SetTime(0.0);
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It does, but that's just the way it is. In my system I made a Time property that calls it twice and a MoveTime method that only calls it once.
     
  5. KalOBrien

    KalOBrien

    Administrator

    Joined:
    Apr 20, 2021
    Posts:
    89
    I'll forward this to the team and see if its a bug or intended as it does look a bit odd to me.
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I reported it a few years ago (case 1005591) and got this response (the link to the original case asks me to log into FogBugz but I don't have an account):

    We have identified this issue as a duplicate of an existing one and we will be closing the issue.

    I've reached out to developers and they said that it's the expected behavior as "SetTime changes only the current Time of the playable.
    https://docs.unity3d.com/ScriptReference/Playables.PlayableExtensions.SetTime.html

    To make it work you need to call SetTime twice in a row to also change the previous Time."

    You can track original case's status here:
    https://fogbugz.unity3d.com/f/cases/994081/
     
  7. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Any news on this?
    I'm looking to have root motion applied when replaying an AnimationClipPlayable and it does NOT apply any root motion unless I call SetTime(0.0) twice on that clip playable.
    If I call it once it will just reset the entire gameobject position back to the animation initial start position.
    The animation has root motion, the Animator has "Apply Root Motion" enabled.
     
  8. zalogic

    zalogic

    Joined:
    Oct 6, 2010
    Posts:
    273
    Yes, but it still doesn't make any sense why calling "SetTime(0)" twice applies root motion from where the animation last finished and calling it once it resets the gameobject back to its original animation position even though the "Animator" component has "Apply Root Motion" enabled.