First I am quite annoyed because I couldn’t reproduce your bug, which seems fair because your general way seems correct. Maybe you want to dig around because your screenshots comes from bigger scenes and not just the DialogUI
I can however propose what I think are general improvements, that will help you to tackle bugs more easily in the future
First
you are using the get_node() function to get the node you are currently on $".".hide() this can be improved by a direct call hide() allowing you to skip the call and making it more readable
Second
If you are handling an inner node it is always good pratice to cache it, ie instead of var label_node = get_node() each time you call the function and then calling the get_node again, you could store the variable in the class scope with onready annotation
Third
It looks like you mix both ways of handling inputs, you can find a good insight here about that:
Summing everything gives us that:
extends CanvasLayer
signal text_box_closed
@onready var label_node = $Panel/Label
func _ready():
hide()
func display_text(text: String):
show()
label_node.text = text
func _input(event):
if event.is_action_pressed("ui_accept"):
hide()
text_box_closed.emit()
elif event.is_action_pressed("ui_cancel"):
display_text("ui_cancel is pressed")
await text_box_closed
# This can be done alternatively
func _physics_process(_delta):
if Input.is_action_just_pressed("ui_accept"):
hide()
text_box_closed.emit()
elif Input.is_action_just_pressed("ui_cancel"):
display_text("ui_cancel is pressed")
await text_box_closed
Once again, I’m sorry I could not tackle the bug directly, but your current scene seems fine so well done and don’t give up.
Thank you for your reply!
I’ve looked through the code you presented and adjusted mine to it. Unfortunately, it didn’t fully solve the issue, but we are making progress towards it.
The code generally improved, but the error message is still there. However, it changed. Before, every time I pressed “ui_cancel” I would get this error, but now it only appears once I start the game. The text also displays just fine.
So the only thing left is to look for a reason for the error’s origin.
Maybe it is because the parent of the scene is a canvasLayer? I really don’t have an idea, but I will keep looking for it.
Thank you for your motivating workds at the end, it really means a lot to me.
If I find a solution, then I will send it in, until then =)
Hey man,
so I’ve got news. After working a bit on the script and looking for ways to further otimize or change it, I’ve learned that the text cannot be displayed, because the label does not exist in the script.
Now this causes the label to not display anything as it does not exist in the script!
But…why?
I don’t understand why this would be the case, as it is prefixed or dragged in, it doesn’t make any sense.
I also changed from Canvasayer to Control, but it didn’t do anything. Was worth a try I guess.
So what now?
It clearly is a bug and not an issue from the coding perspective…
Anyway, thank you so much for your help man, I now have a bette rpicture of what is going wrong and maybe it helps me to find a workaround to ddge the problem.
but unfortunatlely, it didn’t work. It might also be that I misunderstood what you meant, I am sorry in advance if that is the case. The issue still persists.
If I am wrong in that assumption, please corrdct me. I just don’t know what to anymore with that issue
ye, try put the await get tree create timer function, and tell if it works, else you will need a better way to put the dialog_ui, from what i see, your dialog ui is now as Autoload node?
Correct, it is an Autoload script.
I also added the timer you were talking about, but the error message still exists and the print($Panel/Label) still returns null.
You might be right about the engine beeing the problem, would upgrading my engine possibly change the outcome?
However, before doing that I would try making a new UI script, or change it.
Never thought adding a textbox would be this problematic
dont autoload a scene with nodes, i think
because the node is never ready if it’s not inside main Scene tree, hence why it will never work
use autoload to send signal or save variables, as a node.
what you can do now is to make a signal in the NewDialogUI autoload node with this script:
extends Node
signal set_display_text(text)
then in your world script, to trigger the display text function:
NewDialogUI.set_display_text.emit(text)
because it’s a signal, you will need the DisplayUI Node script to connect it by this code: