Godot Version
4.4
Question
I am following this Ultimate Intro to Godot 4 video, and I have an Area2D node called Laser. The attached script, laser.gd, listens to Laser’s body_entered signal:
func _on_body_entered(body: Node2D) -> void:
if body.has_method("hit"): #or if "hit" in body
body.hit()
print("laser entered " + body.name)
queue_free()
This works fine most of the time. However, I just added a couple of new objects to the game that are not triggering this code when I fire a Laser at them. These are both instances of a custom type called GenericObject, which extends StaticBody2D:
extends StaticBody2D
class_name GenericObject
func hit():
print("object")
Here’s a screenshot of one instance, Box:
Here’s the associated script (replacing the parent script inherited by default):
extends GenericObject
func hit():
print("toilet")
For comparison, here’s another object called Gate with the same base type (no further inheritance in this case) and collision layer / mask:
Here’s the overall node hierarchy for the level I am testing:
When I run the level and fire a laser at the box, it goes right over. If I fire at the gate, it collides and triggers Laser’s _on_body_entered
code. This is inconsistent with the tutorial I am following, in which the Box also collides with the laser. Can anyone explain the difference?