Adding sprite to scene on a hidden mesh's position let sprite disappear

Hi there,

I have a really weired situation at the moment where my sprites disappear when I add them at a hidden mesh’s position.

Let me explain what am I doing.

I have a .glb model with planes in there. Those planes get replaces by sprites as “hotspots” to get infos about different parts of that model. So traverse through the model to get those specific planes and get the matrix and position of that planes to apply them to the sprites. After applying all that I set the visibility of the planes to false. Now when I click on oh my “hotspots” all the sprites disappear and I can’t figure out why this is happening.

Here some code for you:

var spriteManagerHS = new BABYLON.SpriteManager("hsManager", "/images/icon_hotspot.png", 5,  {width: 256, height: 256}, scene);
spriteManagerHS.isPickable = true
var matrix = scene.getMeshByName('__root__').getWorldMatrix();

scene.meshes.forEach(m => {
  if ('hs_') !== -1 &&'_sprite') === -1) {
    m.position.y = -2;
    m.isPickable = false;
    m.isVisible = false;
    var hs = new BABYLON.Sprite( + '_sprite', spriteManagerHS);
    hs.playAnimation(0, 34, true, 50)
    hs.size = 2;
    hs.isVisible = true;
    hs.position = BABYLON.Vector3.TransformCoordinates(m.position, matrix);
    hs.isPickable = true;

Thank you in advance!

Hi Rico, welcome to the BabylonJS forum!

It would be nice if you could build a playground that reproduces the issue exactly. Perhaps 3 basic box shapes, each with a plane nearby/parented… and then… everyone can experiment with your markerPlane-to-sprite conversion.

I have one idea… maybe two. hs.playAnimation(0, 34, true, 50) … if you can turn THAT OFF temporarily, it might be wise. Just for tests.

Another idea… use m.setEnabled(false) instead-of m.isVisible = false … something to try… see if issue/symptom changes.

Not shown, but… is there some code that runs when you click on sprite? Do they have click-handlers on each, or maybe a centralized spriteWasClicked() handler function? (sorry, I don’t have much experience with sprite-clicking)

Inside that spriteClickHandler code… you could have something wrong. You set isPickable false on the planes, and isPickable true on the sprites, so I assume you want the clicks to happen upon sprites and NOT upon the old marker planes.

hs.position = BABYLON.Vector3.TransformCoordinates(m.position, matrix); is apparently working correctly, because you DO see all the sprites… in the correct positions… before you do that evil make-all-my-sprites-disappear first-click.

After that first-click, and the sprites all disappear, console.log(everything you can). Try to determine what changed… in the sprites or their manager. Were they hidden by something blocking their view? Were they set disabled or invisible, somehow? Examine your sprite click-handlers very carefully… if you have some installed.

It might be wise to set ALL your loaded mesh, including ground… isPickable = false (before you run your converter code shown above). In doing this, we are trying to ensure that no sprite-clicks are ACTUALLY picking nearby mesh, instead.

It might be fun to try an older version of BabylonJS, too… see if anything is different.

Ok, that’s all I have. Stay tuned for more/wiser ideas, think about making a demo playground for us, and report any discoveries you make. thx!

Totally agree with @Wingnut here, a playground would be more than welcomed.