Access Playing animation time / normalizedTime by script

I checked the C# API references for AnimatedModel, Animation, Animation.InfoData, etc
But I can not find how to get the time of currently playing Animation.

How do I check the time of an Animation,
for example, if I have an Animation with duration of 2.0s,
and when the animation plays at 1.5s I want to trigger something.
How can I check this by script?

And if I can not access it,
What would be the best way to check if an animation is 80% played
or even 100% to check whether the animation stops playing or not?

(I know I can set an AnimEvent at the animations, but this only works for small amount of animations where you can set it by hand one by one.
But if you want to process a huge amount ot animations. It is better to check it by script instead of attaching AnimEvent for every Animations.)

We can add new API to access a list of all currently played animations (including their blend weight, time, and normalized time). I added task to do it to Flax 1.8 roadmap.

1 Like

That would be awesome! Thanks

Added here: Add events tracing feature to Animated Model for animation playback i… · FlaxEngine/FlaxEngine@6d58883 · GitHub.

Example usage:

animatedModel.EnableTracing = true; // call once for tracked actor
var traceEvents = animatedModel.TraceEvents; // call every time to access events from last update
// iterate over events, animation sample node emits animation asset and frame position of the playback (divide by anim Duration to get normalized time)

example usage inside editor to show animation playback debugging: Add displaying playback position of animation in Anim Graph window · FlaxEngine/FlaxEngine@af0439f · GitHub

1 Like