Use queue_free() on one instance of an object

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By R9_dev

I have a building game and I want to queue_free() the object I click, but when I try, every instance disappears. How do I solve that?

Hard to say without seeing some code. Post the code in question.

jgodfrey | 2023-03-13 02:20

:bust_in_silhouette: Reply From: Marco-

Try adding an Area2D with an CollisionShape2D to the buildings. Then connect the input_event signal from the Area2D to a script that is attached to the building.
In there do your logic as you need and try

func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):

Hope this works :slight_smile: