Using onCollide for camera? How to unregister the event?

Dear fellow BJSers,
I was checking for a solution to detect, at a specific time only, either collision or intersection of a mesh with the camera. I found the onCollide suitable running into a registerBefore function. However, I’m having the issue that I’m unable to unregister the event. Seems like ‘onCollideEvent = null’ does not do anything.
Can I remove this camera.onCollide function/event at a given time. If yes, how? If no, I will look for an alternate solution. Thanks in advance :grinning:

onCollide should only trigger when it is implemented. i.e. camera.onCollide = null should stop the event from triggering. Is it not the case?

No, unless I messed it up.
Let me quickly try create a repro in the PG.

1 Like

OK, here’s my PG

Press 2 to unregister the beforeRender function (seems to work, works in my scene).
Press 1 to attempt remove the event.
Check the console log.
I tried variants of this but without success… Thanks,

I am not sure why you use onCollideEvent to remove the onCollide :slight_smile:

EDIT - to be more exact - you need to use camera.onCollide = null to remove it. If you saw somewhere in our documentation that you need to use onCollideEvent please let me know so I can fix it.

1 Like

Oh, Gosh. No actually, I didn’t find anything in the doc for how to remove the event. So I relied on the PG examples search from the API page. That’s where I got this crap from.
Thanks once again for your invaluable help. Just saved me a lot of time and troubles yet once again :smiley:

1 Like