Player interacting with every object

Godot Version



I made a system where if you walk up to an object and press the Interact input then a dialogue box shows up with something written there for each object. Basically what undertale and a lot of other games do. So the way I have it set up is that I have an area2d for every interactable object and when the player enteres the area 2d it sends a signal to the player node which sets the “can_interact” variable to true, and the same thing for when they exit but setting can_interact to false instead. If can interact is true and the player presses the interact input, then itll send a signal to the object to play the dialogue. But the game has no way of knowing what object’s area2d you’re in. So if you go into the area2d of any interactable object and press Interact, then itll show the dialogue for every interactable object.

(The script for the area 2d of every object. The only difference between objects is the dialogue file they play.)
(Player scripts for interacting)
(Node structure for 2 objects)

1 Like

Don’t you have a name to use for each area that you can set as the current interactable object?

i ended up fixing it by handling everything in the area2d node without any signals to the player but please help me with my next issue making this system

Set a variable to represent the current interactable object.
The interaction signal should carry the source itself, and only the object stored in this variable should be triggered when the player interacts.


var interact_object = null

func _on_area_enter(object):
    interact_object = object

func _on_area_exit():
    interact_object = null

func interact():
    if interact_object != null: