+1 vote

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?

in Engine by (97 points)
edited by

2 Answers

+6 votes
Best answer

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.

by (123 points)
selected by

Thanks guys,

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

+1 vote

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

by (847 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.