onAnimationEnd() function triggers on first frame


I am having issues with the onAnimationEnd() function used with an animation. It appears to be triggered at the beginning of the animation as opposed to the end.

Here is a playground: https://playground.babylonjs.com/#1GMTDN#10

Here is my desired result:

  • Click on mesh, animate camera position.z and GUI rectangle alpha
  • When the animation is complete (rect. alpha = 1.0), it removes an asset container from the scene and adds a new asset container, all behind a fully opaque GUI rectangle control.
  • Fade the GUI rectangle alpha back to 0, revealing the new assets added from the asset container

Right now, the asset containers are removed and a new one is added when the mesh is clicked, before the GUI rectangle animation is complete. Is this behaving as intended?


asking @RaananW :slight_smile:

Thank you, Delkatosh. I am not sure if I am using this incorrectly or if it is a bug.

@Deltakosh @RaananW Hey, Iā€™m just curious if this should be listed as a bug. I am still having a trouble with this.

well, you are calling the code by yourself :slight_smile:

fadeAnim.onAnimationEnd = switchScenes();

this will call switchScenes immediatly and store the result in animationEnd :slight_smile:

Furthermore, the onAnimationEnd is on Animatables:

let anim = scene.beginAnimation(rect1, 0, 30, false);
anim.onAnimationEnd = switchScenes;

Here is a better PG:

1 Like

Thanks for clearing that up!