Setting label text throws a 'null instance' error

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By grol
:warning: Old Version Published before Godot 3 was released.

Hey there,

I try to set the text of a label but get the following error:

Attempt to call function 'set_text' in base 'null instance' on a null instance.

I use the following code:

get_node("info").set_text("test")

Any ideas?

:bust_in_silhouette: Reply From: batmanasb

Your get_node(path) failed to find the path to the node and returned “null”. Make sure the path is correct.

:bust_in_silhouette: Reply From: turgotZ

Depends on where you are using that code in relation to the node you want to change?

  1. If the node info has the script attached try just
    set_text("test") or self.set_text("test")
  2. If your script is attached to a different node which is within (child of info ) try
    get_parent.set_test("test")
  3. If node info is a sibling to the node with the script try
    get_node("../info").set_test("test")

The structure of nodes is the key.

Thanks guys,

I really thought the node names are absolute and i can call them from anywhere.
Now I understand.

grol | 2016-03-23 10:14