onPointerDown only able to set once?

I’m trying to understand if this observable only can be registered once or if I’m doing something wrong or if it’s a possible bug. I’m unable to set multiple listeners in my case:

https://www.babylonjs-playground.com/#8U4N05#1

Just some clarifications on what’s going on.

Hey @i73,

From the look of your PG, it looks like you’re overwriting the value for scene.onPointerDown rather than appending a new function onto it.

1 Like

I thought as much, what’s the proper way to add an observable in this case?

@i73 : You seem to have two functions that are the same except for the console print out - and it just runs the last one.

This is how I use that function - now it detects the different objects and prints accordingly

My PG

But then I’m no coder :grin:

cheers, gryff :slight_smile:

Yeah I’m registering a listener with both of the “Functions” I tried your Playground and:

While this isn’t an elegant solution, this is one that I came up with:
https://www.babylonjs-playground.com/#8U4N05#3

The idea is that you take whatever the value is for onPointerDown, copy it to a var, and overwrite it with the old, then the new.

1 Like

@i73 Please try again - I had the wrong link - changed it now
cheers, gryff :slight_smile:

1 Like

Thank you! Just so I’m clear there’s no real solution to this?

I’m used to adding event’s to listeners with += so I’m new to this.

Oh thanks so much Gryff, but that’s not what I’m trying to do, I’m trying to register multiple observers to the scene click event, not pick info click.

No problem. As far as a real solution, this should work for all intents and purposes. onPointerDown is a function data type property so it can only store one function. If you just cache the old value and execute it in the new, it should work just like appending/concatenating.

1 Like

I think this is how I would do it.

https://www.babylonjs-playground.com/#8U4N05#4

Just use the observable and check that the pointer event type is what you are watching for.

2 Likes