Lately I've run into some problems using Godot's built in drag and drop functions. I would like to delete the node right after I start dragging, but I also need the data from the node. I would like to queuefree the node in _getdragdata() (Godot 4), but I first have to return the data. If I queuefree the node in the getdrag_data(), it now doesn't exist therefore I can't return the data within the script. Is there a better workflow for this or is there a way to execute code after I return the data? I've had to resort to setting a kill timer which makes the code lengthy and clunky.
extends Control
var is_active = false
var item_data
func _set_image():
$MarginContainer/Shape_Image.texture = load(item_data.shape_image)
func _clear_slot():
$MarginContainer/Shape_Image.texture = null
is_active = false
item_data = null
func _get_drag_data(position):
if is_active == true:
var kill_timer = Timer.new()
kill_timer.connect("timeout",Callable(self,"_clear_slot"))
kill_timer.wait_time = 0.2
kill_timer.one_shot = true
add_child(kill_timer)
kill_timer.start()
return item_data