simple fix to my spawnpoint (input issue)

Godot Version 4.3

Im making a spawnpoint for custom Item resouce, it workes fine untill i added the interaction, i suspect the problem is that the try_pick_up() runs immidietly after entering the area2d and no human is fast enough to press the button in time. any and all help would be appreciated
here is the code:
extends Node2D
@export var spawn : Item
@onready var pick_up_l: Label = $pick_up_l

func _ready() → void:
var inst = spawn.scene.instantiate()
add_child(inst)
pick_up_l.hide()
func try_pick_up(body: Node2D):
pick_up_l.show()
if Input.is_action_just_pressed(“Interact”):
body.on_item_pick_up(spawn)
queue_free()
func _on_area_2d_body_entered(body: Node2D) → void:
#print(“hfdkjfd”)
if body.has_method(“on_item_pick_up”):
try_pick_up(body)
func _on_area_2d_body_exited(body: Node2D) → void:
pick_up_l.hide()

What’s the issue? What do you expect to happen vs what really happens?

Make sure to paste with formatting

i solved the issue using _unhandled_input() and a bool, i would still appreciate feedback if anyone has some useful knowlege to share

new code: extends Node2D
@export var spawn : Item
@onready var pick_up_l: Label = $pick_up_l
var i_area : bool =0
var spiller : Node2D

func _ready() → void:
var inst = spawn.scene.instantiate()
add_child(inst)
pick_up_l.hide()
func _on_area_2d_body_entered(body: Node2D) → void:
if body.has_method(“on_item_pick_up”):
pick_up_l.show()
i_area = true
spiller = body
func _on_area_2d_body_exited(body: Node2D) → void:
pick_up_l.hide()
i_area = false
func _unhandled_input(event: InputEvent) → void:
if event.is_action_pressed(“Interact”) and i_area:
spiller.on_item_pick_up(spawn)
queue_free()

sorry about the formating i will do that in the future

If you need something to wait on a particular input/signal, the “await” keyword can’t be beat. If you want something to just delay, look at tweens.

1 Like

yes i thought about using await but if the player dont want to pick up the item it will be awaiting forever right?

I guess I don’t really understand what the problem was, sorry.