Godot Version
Godot 4
Question
Hello!! I am trying to create logic in which when the player enters the Area2D of an NPC, a dialogue box will appear. Currently I have the collision set to display the dialogue box by setting the Control Node to visible, but anything that I try does not work. I tried the set_visible(true) as well as .visible = true. I will attach the code below!
NPC Collision Code
func _on_area_entered(area: Area2D) → void:
if area.get_parent().name == “Player”:
if get_parent(): # Ensure the NPC has a parent
npc_name = get_parent().name
print("NPC name: ", npc_name)
path_follow = get_parent().get_parent()
path_follow.speed = 0
UILogic.display_dialogue()
print(“NPC has stopped”)
else:
print(“NPC has no parent!”)
else:
print(“Colliding area or its parent is missing!”)
Global UILogic Script/Code
extends Control
func _ready():
pass
func display_dialogue():
self.visible = true
Godot Hierarchy
This is the scene that the UI Logic code is attached to
This is the hierarchy for the main scene that I am trying to use the visible toggle in
Main Question
I am not sure if it is code I am not implementing correctly, or if I need to set the visibility off somewhere before. I toggle the visibility to be off before running the scene in the main scene, it is just not reflected in the screenshot. I am hitting a wall and unsure of what to do. Thank you!