Bug: Sprite Not Appearing After Multiple Clicks When Recreating SpriteManager

I’m encountering an issue with BABYLON.SpriteManager when dynamically recreating sprites and their managers upon user interaction. Specifically, when I click on a mesh twice in a row, the sprite does not appear as expected.

Expected Behavior

  • Each time the mesh is clicked, the existing sprite and SpriteManager should be disposed of, and a new sprite with a new SpriteManager should appear.

Actual Behavior

  • After the first click, the sprite appears as expected.
  • On subsequent clicks, the sprite does not appear, even though the code for creating a new SpriteManager and sprite executes without errors.

Observations

  1. The issue seems to occur only when the sprite and SpriteManager are recreated on consecutive clicks.
  2. The console log (scene.spriteManagers[0].sprites[0]) correctly shows the new sprite on subsequent clicks, but the sprite does not appear in the scene.

Are there any best practices or workarounds for dynamically recreating sprites and SpriteManager instances?

Thanks in advance for your help!

This PR will fix the problem:

Hi,
I’ve tested the snapshot, and everything works perfectly! The issue with the SpriteManager crashing is resolved. Thank you for the fix!

To verify, I created a test Playground using the snapshot:
Babylon.js Playground

Out of curiosity, do you know when this fix will be included in the official release on the CDN?

Great work, and thanks again for the quick resolution!

The Playground will be updated tomorrow and the CDN on next Thursday.

Thank you for the quick response!
I’ll keep an eye on the Playground update tomorrow and the CDN release next Thursday.
Really appreciate the support and the quick turnaround! :blush: