queue_free not working

Godot Version

4.6.2

Question

I am making a game where you have to click tiles and I need to delete the tiles (StaticBody2Ds) after they have been clicked but queue_free() doesn’t do anything

(I am new to godot and don’t know much gdscript but the internet said to use queue_free)

I don’t know how to properly send my code but here:

extends StaticBody2D

@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
@onready var timer: Timer = $Timer

var IsClicked = false

func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) → void:
if Input.is_action_just_pressed(“click”) and not IsClicked:
animated_sprite_2d.play(“clicked”)
IsClicked = true

func start_the_timer():
if IsClicked:
timer.start()

func _on_timer_timeout() → void:
queue_free()

You never start the timer.

how long is the timer set for in the inspector, or try adding a time duration in the timer.start

func start_the_timer() -> void: #this function will not return anything
    if IsClicked:
        timer.start(1.0) # this will have a duration of 1 second

your start the timer function is not marked void, meaning it needs to return information, if you don’t want it to return anything the mark it will void.

That’s not the problem here. The problem is that, based on the provided script, the start_the_timer function is never called, hence the timer never starts.

is the whole script here and is the function global? that could be happening, but you also have a point tibaverus

For getting help much easier and smooth, please do format your code by hightlighting it and pressing Ctrl + E while making the forum post. It is hard to read it in plain text and formatting it would get more people to try and help you.

class_name CodeExample

var placeholder_var: float = 12

And to solve your issue, the function start_the_timer() is never called and that’s why the expected behaviour is not happening. You can call the function at _on_input_event(). Also make sure to print something at the end there as well to make sure _on_input_event() function is being called.

func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) → void:
    if Input.is_action_just_pressed(“click”) and not IsClicked:
        animated_sprite_2d.play(“clicked”)
        IsClicked = true
        start_the_timer()
        print("Started the timer!")

If nothing is happening still, the other problem could be that Timer’s timeout signal is not connected to the on_timer_timeout() function so make sure the signal is connected as well.