How to get the actual time of an animation that is playing?

Hello,
I’m importing a baked animation, and I’m using it as animationGroups[0].
https://playground.babylonjs.com/#IQPBS4#3
I should do some stuff when the animation is, for example, at 50% of the lenght.
How can I know the actual time of an animation that is playing?
I’ve looked in the docs of the " AnimationGroup" Class

but I can’t see any property of method for it.
Many thanks!

1 Like

IDK if there’s a better or easier way, but you can for example drill down to one of the RuntimeAnimation objects and see what frame it’s at, then divide by the number of frames to get a progress value.

Note, this is based on the assumption that all animations in the group are normalized to have the same number of frames and that they start at frame 0. This is already true in this case for the your PG, but animationGroup.normalize could be used if it wasn’t.

Here I logged this progress value every 50 ms for example. :slightly_smiling_face: :beers:
https://playground.babylonjs.com/#IQPBS4#14

5 Likes

This method also needs to write a timer. Is there any callback function added in animation

You could try using onAfterAnimationsObservable for the callback if you want to calculate the progress each frame, after the animations have advanced. :slight_smile:

2 Likes

I think each Animation can be added with an animations observable. If there are many animations, it will be very troublesome to use scene’s onafteranimations observable.
What’s your opinion?

It is recommended to encapsulate an animation progress monitoring function

3 Likes

Ooh that looks like a good idea! :slight_smile:

Have you ever thought of making PR

How do you actualy get an animatable from an animationgroup or an animation?

The animatable only has a list of animations. I am not sure what you want to do in your use case ?

I want to use the onAnimationProgressObservable as @brightMoon mentioned before. I thought Its a property of an Animation but its a property of an animatable, so I need an animatable from the animationgroup

I think that property never got added but is a good suggestion IMO, although I’m not sure how some of the details would work… :thinking:

Yup this property does not exist

Ah right, I just realised its an edited Screenshot from the documentation :joy: my bad I thought the property exists

Get animation return for each frame

on animationGroup you simply access through animatables and then you can list animations.

on animation, it do not think it makes sense as there is only one animation

2 Likes

Meaningful. For example, if there are 10 frames of animation, I need the return value of each frame of animation, and then perform business logic operations