Hello,
I’m not sure if this is a bug, but I’ve been doing some tests today, and if I do the next:
const playAnimation = () => {
// Clear observable and stop previous animation
this._animation.animationGroup.onAnimationGroupEndObservable.clear()
this._animation.animationGroup.stop()
// Start mesh animation
this._animation.animationGroup.start()
// Trigger observable on animation end
this._animation.animationGroup.onAnimationGroupEndObservable.add(() => playAnimation())
}
The third iteration triggers the observable lot of times, and the fourth iteration triggers it non stop.
I’ve tried different things and I can’t avoid this situation. notifyIfTriggered
is false.
Instead, using a setTimeout
, the code above works fine, iteration by iteration.
const playAnimation = () => {
this._animation.animationGroup.stop()
this._animation.animationGroup.start()
setTimeout(() => {
playAnimation()
}, 5000) // Some arbitrary time similar to animation end
}
Some idea?
If you think it worth to be reviewed I’ll create a PG.
PS: Waiting a frame before calling the new observer prevents the situation:
const playAnimation = () => {
// Clear observable and stop previous animation
this._animation.animationGroup.onAnimationGroupEndObservable.clear()
this._animation.animationGroup.stop()
// Start mesh animation
this._animation.animationGroup.start()
// Trigger observable on animation end, calls callback 1 frame later
this._animation.animationGroup.onAnimationGroupEndObservable.add(() => {
setTimeout(playAnimation, 1)
})
}