How to exclude particular CSG object from physics queries?

Godot Version

4.2.2

Question

I’m making a plugin for the editor to ease object positioning and that involves raycasting. The problem is: I want to exclude CSG children of a node from raycasting, but I don’t see a way to get their RID to pass as exclude in intersect_ray, and they immediately get in the way, blocking the real intersections I want to capture.

These CSG children have “use collision” flag enabled. I do see some RID once I get the raycast result, but I need that RID beforehand (otherwise I will have to continuously run queries while adding each new RID of each CSG by one at a time).

How do I get RID of CSG to not query them?

P. S. I can see in the sources that root_collision_shape is not exposed, so it seems there’s no way to get RID at the moment?..

P. P. S. It’s also not possible to get RID by object instance id (the one attached in the source code) either…

Put your CSGs on a different collision layer and do not use that layer in the raycast.

1 Like

No, this is not the solution, because I do need to raycast against other, non-selected CSG-s in the scene, I need to exclude only the currently selected ones (transitively, i.e. CSG-s of currently selected nodes as well)

A ray cast can only bypass an object if it is not setup to collide with it via the collision layer or by adding it to an exception list.

If you are “selecting” objects you should then save a reference to each object and add them to the raycast exception table.

Yeah, this is what I’m asking about. I can easily do this for children Area3D / PhysicsBody3D as they all have RID. But not CSG shapes, so they can be used neither with PhysicsDirectSpaceState2D.intersect_ray() nor with RayCast3D.add_exception().

Any other ideas?

All resources have an RID. If there is a collisionobject node that uses a CSG for its collision shape it will be registered with the physics server under the rigidbody, staticbody, or area.

Checkout the link, I originally posted. As you can see in the sources, CSG shape does create a body and a shape internally - even stores the RID and attaches object instance id to the body - but I cannot find a way to get it.

That’s what the question is: how do I get a RID of CSGShape’s collision object? Or, alternatively, how do I exclude particular CSGShape from physics queries like intersect_raycast?

To me it looks like it is impossible, but I wanted to ask a question first before I file an issue on GitHub


I updated topic title to be more concrete

I see now, you could potentially probe them like this but it is not convenient.

	if $RayCast3D.is_colliding() :
		var col = $RayCast3D.get_collider()
		if col is CSGShape3D:
			$RayCast3D.add_exception_rid($RayCast3D.get_collider_rid())

You could change the type check to some meta data if you want.

Thank you for your reply.
For anyone coming to this later - I filed an enhancement request here: Expose RID of CSG collision instance · Issue #10130 · godotengine/godot-proposals · GitHub

1 Like