Area not moving when interracting with another area

Godot Version

4.6.1.stable

Question

Hello! I’m trying to make my game character to move a body into the grave. I created a very simple script for testing but it is not working and I can not see what I am missing.

func _ready(): #This just declares where objects are at the start
	$PlayerWorld.position = $PlayerPosition.position
	$Grave.position = $GravePostition.position
	$DeadBody.position = $BodyPosition.position


func _on_dead_body_area_entered(_area): #Here I connected a signal from the body which should update the position if the button is pressed. I don't understand why it doesn't.
	if Input.is_action_just_pressed("interract"):
		$DeadBody.position += Vector2(50, 0)

Thank you in advance for answering!

The function _on_dead_body_area_entered ONLY runs for a single frame, when the body actually enters said area. This will only work if you somehow press the interact button on the exact same frame when the body enters. I instead recommend keeping a boolean in your script, that changes based on if the body is inside the area or not. Connect your body entered and body exited signal to two different functions. When the body enters, set that boolean to true, when body exits, set it to false. Then you can simply run a code in process that checks “If the interact button is pressed AND my boolean is true, do this thing.”

Thanks for the explanation, I’ll keep that in mind.