Need help with destroying objects

Godot Version

Godot 4.4.1

Question

I'm making a doctor who fangame where the player can use sonic screwdriver to interact with objects, i used a tutorial and managed to make so that the area2D as a hitbox will appear during the animation and if it touches something in a group of "mechanic" it will use the func breaking(). But it doesn't work for me even as a test. Here's the code i used for the player character:func _on_area_2d_area_entered(area: Area2D) → void:
if area.is_in_group(“Mechanic”):
if area.has_variable(“SonicPitch_req”) and SonicPitch == area.SonicPitch_req:
if area.has_method(“Breaking”):
area.Breaking()`

and here’s what i used for the staticobject2d that it needs to call

`extends StaticBody2D

var SonicPitch_req := 2 # Change this per object

func Breaking():
print(“Mechanism activated!”)
$CollisionShape2D.disabled = true
$Sprite2D.hide()
`
I would be glad if someone can help a starter developer, because even ChatGPT can’t help.

Welcome to Godot. Look forward to seeing what you create.

I believe the call you are looking for is queue_free. That deletes the object from the system.

func Breaking():
  print(“Mechanism activated!”)
  $CollisionShape2D.disabled = true
  $Sprite2D.hide()
  queue_free()

Going forward, if you have code you want to share on the forum please put it in a preformatted text box. Makes it a lot easier to read :slight_smile:

1 Like