← Pixel Dreamer Studio

An Area3D that does not see a bullet or another area

Listen to the right signal, keep Monitorable on, and set masks by layer number, not by the number you see.

An Area3D reports other areas only through area_entered, and bodies only through body_entered. In our Godot 4.7 test a hurtbox connected to body_entered caught a bolt that was an Area3D 0 times, and caught it once with area_entered. The other common cause is the mask: collision_mask = 3 in code means layers 1 and 2, because the number is bits, so a bolt on layer 3 was missed. set_collision_mask_value(3, true) turns on layer 3 itself. The script below names the reason for any pair.

The code

Save it as hit_check.gd and call it once while you debug, from the hurtbox or from anywhere that has both nodes: for why in preload("res://hit_check.gd").why_not(hurtbox, bullet): print(why). Each line is one reason the hurtbox will not report the bullet. No lines means it will.

extends RefCounted
## Says why an Area3D does not report another area or body, or that it should.
## Call it once while you debug, for example from your hurtbox's _ready():
##   for why in HitCheck.why_not(self, bullet): print(why)
## An empty list means the two can see each other.


static func why_not(watcher: Area3D, other: CollisionObject3D) -> PackedStringArray:
	var out := PackedStringArray()
	if not watcher.monitoring:
		out.append("%s has Monitoring off, so it reports nothing" % watcher.name)
	if other is Area3D and other.get("monitorable") == false:
		out.append("%s has Monitorable off, so other areas cannot see it" % other.name)
	if (watcher.collision_mask & other.collision_layer) == 0:
		out.append("%s's mask (%s) has none of %s's layers (%s)" % [watcher.name, layers(watcher.collision_mask), other.name, layers(other.collision_layer)])
	for n in [watcher, other]:
		if not has_shape(n):
			out.append("%s has no enabled CollisionShape3D with a shape" % n.name)
	var wanted := "area_entered" if other is Area3D else "body_entered"
	if watcher.get_signal_connection_list(wanted).is_empty():
		out.append("%s is a%s, so it shows up in %s, and nothing is connected to that" % [other.name, "n Area3D" if other is Area3D else " body", wanted])
	return out


static func layers(bits: int) -> String:  # 5 -> "layers 1, 3"
	var l := PackedStringArray()
	for i in 32:
		if bits & (1 << i):
			l.append(str(i + 1))
	if l.is_empty():
		return "no layers"
	return ("layer " if l.size() == 1 else "layers ") + ", ".join(l)


static func has_shape(n: Node) -> bool:
	for c in n.get_children():
		if c is CollisionShape3D and c.shape != null and not c.disabled:
			return true
	return false

What we measured

A hurtbox, an Area3D with a 1 m sphere, and a bolt with a 0.2 m sphere placed inside it. Each line gives what the hurtbox reported and what the check printed. Two runs gave the same results.

Why it happens

Areas and bodies are reported by different signals, so the one you connected decides what you hear about. Monitoring is whether an area looks, Monitorable is whether others can see it, and the two are separate switches. In the Inspector the layer boxes are numbered 1 to 32, but in code a layer is a bit: layer 1 is 1, layer 2 is 2, layer 3 is 4 and layer 4 is 8. So 3 is layers 1 and 2 together. Only the watcher's mask matters for what it reports, which is why a bullet can hit a hurtbox that the bullet itself cannot see.

What to change

Ready-made bolts: Projectile & Cast VFX for Godot 4 has 41 spell projectiles with their cast, flight and hit. With hit_area on, each bolt carries an Area3D your hurtboxes catch with area_entered, and with hit_body a small body they catch with body_entered, both in the group pd_projectile, and hit_mask and hit_layer take the same bit values described above.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Projectile & Cast VFX for Godot 4 has 41 spell projectiles that can carry an Area3D or a small body for your hurtboxes to catch, on the layer you choose.

More how-tos for Projectile & Cast VFX for Godot 4: Spawn a hit effect facing the surface

More how-tos: Projectiles and aiming