0 votes

I have a reference to a node:

var player
func _ready():
    player = get_node("/root/World/map/Player")

and an array:

var dialogue_1 = [
    "Nice to meet you Somebody",

but when I print:


it gives me Null, what is the proper way to store a reference to a node inside a list?

in Engine by (18 points)

2 Answers

+1 vote

It has nothing to do with storing it in an array. If you try print(player) in _ready() you'll see it's null as well.

You can't call up the tree in _ready() because wherever this node is, "World" is not ready yet. Nodes become ready in reverse tree order - children first, parents last.

by (20,927 points)

I've already tested print(player.name) and got player so I'm pretty sure that part works

+1 vote

Found the problem, my dialogue was defined after the _ready() block but outside it, once I've moved it inside the problem was solved.

by (18 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.