Can multiple CollisionShape3D be grouped or collaborated together?

Godot Version

4.3

Question

Suppose I have many many Area3Ds that overlap with each other. Some Area3Ds may completely be in another Area3Ds. Some may intersect with each other partially.

Is it possible to do something like making all of these Area3Ds share the same on_area_entered and on_area_exited?

So if the player move into an Area3D that has other Area3Ds intersecting, the entered signal will be triggered, and when the player move around to other intersecting areas without leaving the previous area first, no signals will not be fired.

For example, if the player got into second Area3D , then leave the first one afterward, then move into the third Area3D, then leave the second one afterward, no signals will not be fired.

Lastly, if the player moved out of the Area3D completely and not into any other Area3D first, then and only then, will the exited signal be triggered.

Is something like this possible?

You can combine multiple CollisionShape3Ds under one Area3D so that it all acts as one single Area.
See my demo here, these are 3x CollisionShape3D under 1x Area3D with just one script.


This is the scene structure.

This is the script on the area:

extends Area3D

func _ready() -> void:
	body_entered.connect(_on_body_entered)
	body_exited.connect(_on_body_exited)

func _on_body_entered(body: Node) -> void:
	body.get_node("MeshInstance3D").mesh.material.albedo_color = Color.GREEN
	print("body entered")

func _on_body_exited(body: Node) -> void:
	body.get_node("MeshInstance3D").mesh.material.albedo_color = Color.RED
	print("body exited")

And in the console, it printed the following:

body entered
body exited
body entered
body exited

You can see, even though there were 3x CollisionShape3D, the body entered the area only 2 times, the Box and Sphere shapes are treated as one.
Hope that makes sense and you can make use of it.

1 Like