Clarification about Colliders

Hey guys, if I have an object with MeshRenderer and no collider, should a script implementing e.g. IPointerClickHandler be triggered by a mouse click?

Original Post on Discord

by user 395602247196737546

If you have an ObjectRaycaster somewhere above it in the hierarchy then yes (I believe it’s added to the root by default)

We’re doing things a bit different than in Unity: in Unity, clicks always have to go through the physics engine. While that is great if you have a physics engine it’s not great if you want to have a small-as-possible web app, so by default we’re not using physics but instead three’s raycasts (that are relatively slow but operate on meshes directly without physics being involved)

You can set objects to the IgnoreRaycast layer to have them not raycasted at all

Then I’m confused. In the docs it says

Another option is to use the physics raycast methods which will only return hits with colliders in the scene.
const hit = this.context.physics.engine?.raycast();

And that’s looks like what ObjectRaycaster does?
const hits = this.context.physics.raycast(opts);

Or is the difference in the engine?. property?

by user 395602247196737546

Yes it is and it’s also in the docs… Man. I’m sorry to trouble you with all those questions. Hard to wrap my head around this whole thing.

by user 395602247196737546

No problem, keep asking, that definitely all helps to improve the docs. There’s a lot of stuff :slightly_smiling_face:

Yes, with .engine. it will go through the physics engine. Not ideal in terms of naming, I agree

Yep, I think this is the problem in this case. Both having physics in their names and only one actually going through the physics engine.

by user 395602247196737546

Got an alternative idea for the “non-physics” raycast naming?

I can see the point for the smaller footprint by removing the physics stuff though. Is this done automatically if it’s never referenced or how does it work?

by user 395602247196737546

(The name currently comes from the fact that people were looking for “Physics.Raycast” like in Unity and we added that even before actual physics were supported)

You can add a “Needle Engine Modules” component to strip it away - halves your build size!

If you don’t use any colliders/rigidbodies in a scene we log a warning that you may want to strip away, but otherwise it’s opt-out

I’ll try to go without physics and using the IgnoreRaycast layer.

by user 395602247196737546

There are only three hard problems in computer science… :wink:

by user 395602247196737546

(Oh actually it’s two and that’s kind of the joke… :smile: )

by user 395602247196737546

Haha
At some point there may be a third - we may at some point switch raycasts back to opt-in, so you’d still explicitly mark things with colliders but then have a choice of going through physics or not. Yet another approach that would result in more control over raycasts plus no physics engine. But no ETA for that

For now we’re pretty happy with the current approach of “everything is clickable by default and you can opt out for specific objects”

The exact hits are a nice bonus too

by user 395602247196737546