Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What does PlayableExtensions.SetDone actually do?

Discussion in 'Animation' started by Kybernetik, Mar 13, 2019.

  1. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,555
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,555
  3. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Playable that reach the end of their duration are automatically marked as done.
    When all connected playables are done, PlayableGraph.IsDone() returns true.

    In the case of SimpleAnimation, when the graph is done, it is stopped, which stops graph processing, saves CPU, and also stops the Animator from writing to bindings (assuming this is the only graph connected)
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,555
    That doesn't seem to be the case from looking at the code because PlayableGraph.IsDone doesn't actually get checked anywhere.
    • StopGraph is called by the onDone event.
    • That event is invoked in SimpleAnimationPlayable.UpdateDoneStatus.
    • The invocation happens when m_States.AnyStatePlaying() returns false.
    • AnyStatePlaying checks if any states are marked as enabled.
    • The StateInfo.enabled property just wraps a bool field, which is only set to false by Disable.
    • Disable is called in a few places and it goes on from there, but nothing in that chain actually seems to check if a state's playable IsDone.
    • The only place StateInfo.isDone actually gets checked is when updating with WrapMode.Once, which is a manual time vs. duration check that doesn't actually rely on the isDone value.
    So for the PlayableGraph to be done, all its playables need to be done. That includes the SimpleAnimationPlayable, which needs to manually check all its states to determine when it is done. And when it checks the states it checks if they are enabled, not if they are done.

    Clearly I'm still missing a key piece of the puzzle.
     
  5. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    I just double checked the (Unity) code, I was a bit mistaken.
    Playable.IsDone will be set to true when a Playable has reached the end of its duration during playback. You can also set it manually if you want.
    PlayableGraph.IsDone will return true if all the source playable of all its outputs report that they are done.

    So, not all playables need to be done for a PlayableGraph to be done, just the topmost nodes.
    The Done flag is mainly used by Timeline, and it's quite possible that SimpleAnimation doesn't use it to figure out if the graph is Done, as the component does its own graph management.

    And, SimpleAnimationPlayable.UpdateStates uses Playable.IsDone to check if a state is done. It also does some additional checking, for cases where:
    • The state is playing backward (doesn't count as done)
    • The time of the playable was manually set outside the duration (doesn't count as done either, the time must cross the threshold of t1<duration<=t2)
     
    guycalledfrank likes this.
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,555
    Thanks David, that helps clear it up.