The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

Hello all. I made a button that lets players mute the sound effects in my game. The variable "FXon" is in the top level Node/Panel's GDscript. Two layers below that, I have a child node with its own GDscript like this:

Node/Panel (a) -> Node/Control (b) -> Node/Control (c)

I tried this:

onready var globalVars = get_node("/root")
if globalVars.FXon == 1: do_stuff

Every time it got to that line of code, the game hung. So how can I read a's FXon value from c's GDscript? Thanks.

in Engine by (26 points)
edited by

1 Answer

+2 votes
Best answer

With get_node("/root") you will get the root-node of the tree which is a Viewport-node. When you run a scene, that scene will be added as a child of root. So if (a) is called "main", the correct path would be get_node("/root/main").

by (10,634 points)
selected 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 [email protected] with your username.