Whiy is the node not found?

Godot Version


Here we can see that the text of the else: method runs. However the other if block runs as well.

The scrrenshot of the issue:

What I don’t understand is, that the if condition runs, but the else condition runs too. I also get the desired output in the game.

As seen here, the code for displaying the text runs, but I still get the error. I have tried other ways of getting access to the node.

  1. $Panel/Label
    but both of them return the same error message.

is there maybe a slight issue I am missing?
Thanks to anyone looking into this, have a great day!


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

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

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

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():

func display_text(text: String):
	label_node.text = text

func _input(event):
	if event.is_action_pressed("ui_accept"):
	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"):
	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.

I hope it helped!

1 Like

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 =)

1 Like

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.

As seen here: it returns null!

Now this causes the label to not display anything as it does not exist in the script!
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.

yes, too quick to call that node that havent ready
try add

await get_tree().physics_frame 

on the first line of _ready() or before you call the node like that

Thank you for your reply.

I tried what you told me to do:

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

how do you trigger display_text function?

if you put

await get_tree().create_timer(1).timeout

on the first line of display_text function
and it still got an error of no node/null, then something is definitely wrong with your engine

This is my worldScene:

Under the chest is an Area2D;
Once I enter the Area2D this signal plays out:

Here I set the text to be used in the display_text(text) method. Hope this is what you meant.

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 :frowning:

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:


because it’s a signal, you will need the DisplayUI Node script to connect it by this code:

func _ready():

no, it’s not engine problem now, because you are trying to get a node that never be added_child because it’s an Autoload node

above codes should work if you set it properly.


Thank you so, so much man, it worked!

1 Like