0 votes

We can add nodes by doing add_child(node), however how we can store a reference for later use? My expectation was that this was going to work:

Julliet = add_child(Julliet_Template)

However in the editor it says:

Assignment operation, but the function 'add_child()' returns void.

I have researched the topic but nobody is talking about this, this will be very useful for a lot of reasons. Where is the blackmagic? I can't find it. o.o

in Engine by (295 points)

1 Answer

+3 votes
Best answer

The node you add is your reference. In your example, Julliet_Template is a reference to the node you added. I'm not sure what else you're looking for there...

by (10,750 points)
selected by

I was expecting a unique RID from add_child, kind like a unique copy. Because we can add multiple instances using add_child as far as I know. But I can still do this using meta or some sort of reference injection through the parent if say, a child has X var or value. But I see what you mean now. Thanks @Jgodfrey!

Just for details why I thought like this, is because I am used to create some nodes like this:

onready var TWEEN = Tween.new()

func _ready():


    print(name," : feedback 1")

Because we can add multiple instances using add_child as far as I know.

No, that's not true. A node instance can only exist in one place in the scene tree, and therefore can only have a single parent. If you attempt to parent the same node instance to multiple nodes (via add_child) the second one (and beyond) will fail as the instance already has a parent.

You can create multiple instances of the same scene, and add each of them to the scene tree in any location you want. But, each single instance can only have a single parent. And, each instance really is the reference you're after...

Oh I see now, never thought of instances like that. I guess it's my fault for not going far down the rabbit hole enough :D thanks again, you always bring clear answers! +1

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.