i’m trying to buil a car-cannon A (car)mesh moves along an animation, onAnimationGroupEndObservable i want to switch the mesh and rerun the animation. So far, so simple.
However, my onAnimationGroupEndObservable function get’s triggered exponentially with every new run (= 1,2,4,8,16,etc times) .
In the playground (https://playground.babylonjs.com/#7V0Y1I#4587) everything works as expected. In the Project however i encounter the problem. The only difference - as fare as i can tell - is, that in my project i use an animation created in Blender and imported via *.glb
I reproduced all the functions i use in the project. In the playground it works… I thought maybe there is a known issu with onAnimationGroupEndObservable and imported animations or something… Or one of the elders of 3dinthebrowser has an idea what to try?
I’m affraid, i can’t share the hole project in the playground, we’re at 12k lines right now…
Here is a link, if that helps? –> ICT.factory (Please ignore the bussound, it is not yet finetuned…
(One can see the exponentially triggering function in the console)
i would love to user onLoopEnd, however my “switchcar“ functionality doesn’t work then (and i also don’t understand why…)
The idea is that there is an animation (car driving through town) and after every run i switch the car. This animation i want to clone a couple of times to have several cars on the same road on different starting-positions (therefor the random ani.from value).
when i use onAnimationGroupLoopObservable –> https://playground.babylonjs.com/#7V0Y1I#4622 it stops the animation when switching the car-mesh. However, when i restart the animation onLoopEnd manually it seems to work and behaves like i would expect onEnd to work…?
why does onAnimationGroupEndObservable trigger exponentially and why does switching the mesh in onAnimationGroupLoopObservable break the loop, but when restarting it it doesn#t trigger exponentially?
This does not work as expected because you are not allowed to play the same animation in an anim.onAnimationGroupEndObservable handler as the animation for which the handler is currently being called. You should delay calling play by using setTimeout:
Disposing a mesh will also dispose the current animatables linked to this mesh, that’s why it can do strange things in your code.
The best way to handle this case is to clone the animation and assign it to the new car:
You have to set a negative speed ratio when from is greater than to: