0 votes

I'm studying this asset:

In res://Inventory/UI/ItemSlot.tscn, it has this line at the top:
onready var invcomp = getnode("../../../").inv_comp

What does that do?

I understand get_node is supposed to get the node using the node name and its parents. But from what I know "../" is supposed to address its parent. So in this case, it's 3 parents above. The script was added to the highest parent, so I don't know anymore.

Also what does ".inv_comp" do? I see that it's a variable?

in Engine by (39 points)

1 Answer

+1 vote
Best answer

How do you know it is the highest parent? This scene could be instanced inside another scene during runtime. get_node("../../../") returns null when attached to highest parent.

by (158 points)
selected by

Thanks. I understand it now. It's calling a variable in a node 3 parents higher in the scene it is instanced in. This particular node is being added during runtime so it confused me.

You gotta press the tick icon in my answer so that the question doesn't appear as unanswered.

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.