Hey @EvilTwinsNiceBrother…first this is the best username ever!
Second, terribly sorry about the delay. I’ve honestly been spending a lot of time digging into this and trying to figure out why what you have written isn’t working.
I’ve got good news and bad news.
Bad News first - I honestly cannot figure out why adding an execute code action, added to the sprite action manager is not firing. There are clear examples in the documentation of where this feature works just fine, so It’s a bit of a mystery to me. I’m sure I’m overlooking something stupid. @Deltakosh can likely help us.
The good news though is I was able to get the desired behavior you were looking for via a different method. I’m not sure how helpful this is to you, but check out this playground:
https://www.babylonjs-playground.com/#XBPQ23#5
I’ve done a couple of things here. First I changed the onPointerObservable to onPointerDown to fire your function whenever the mouse is pressed.
Second I store the pointer’s x and y position at the time of the click and run a pick operation and make sure there was a hit. This eliminates the bug you had where you’d draw a sprite even if you clicked off of the mesh.
This narrows it down to either a mesh or sprite having been picked.
Next I run another pick but this time just the pickSprite to see if there was a sprite selected. side note you shouldn’t need to do this second pickSprite operation, because I believe that the first pick should return anything in the scene that was picked…including both the sprites and the mesh, but I could be wrong about that…it may just be the FIRST thing that was picked.
If it was a sprite that was picked, then I display the alert
If it was not a sprite, then I use the original pick’s x,y,z positions to draw the sprite on the mesh as you had before.
So this works to get the desired behavior, but it’s a different method than you were exploring, and again, I see no reason why the route you were going didn’t work, so I’m going to do some more digging and see what I can learn.
Anyone else have any ideas?
Bonus: I also add this line of code:
sprite.useAlphaForPicking = true;
It isolates selection of each sprite to the red dot itself.
Sorry I don’t have a more firm answer. I hope this is helpful in some way.