0 votes

When I use getnode, getchild or $, it returns null.

It's just that, I don't know how to fix it. In case it works, his script is an auto load.

in Engine by (106 points)

2 Answers

+1 vote

You can autoload scenes or scripts.

If you autoload scripts, they usually don't have child nodes. They're just single nodes in the scene tree. You could add children programmatically but why?

Scenes usually consist of multiple nodes. In that content get_child() makes more sense.

That said: I guess that you know that many people here successfully use get_node or get_child. So you could derive that your problem is not very common. So how could you come to the conclusion that just your two sentences can help people narrowing down your problem?

If you need furthere help: Please define what you actually want to achieve and for what purpose you will use get_node or get_child. And give us some idea of the node tree (parent, children, where script is attached...)which you expect to exist.

by (3,258 points)
0 votes

Don't autoload scripts, they cant have children.

by (523 points)
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 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.