Hello,
can’t really find answers anywhere online. Is it possible to @export variables from your global script and have them updated with the inspector information or information from another script acting as an inspector remote? It seems like a no and that global information is a constant that can’t be updated but I would very much like to know if there IS a way or what anyone else would suggest besides an unholy amount of signals.
Thanks!
I’m not sure I understand what you want. Do you want to modify @exported variables from an autoload script from within the editor? In that case create a scene and attach the script, and use that scene as the autoload.
Exactly that. Your autoload can be either just a *.gd script, or a whole *.tscn scene. I almost always make my autoloads scenes, because it’s much more convenient to do what you described - applying exported variables and debugging.
What they said. Here’s an example of an Autoload that I made for sound. It’s also a plugin, so I wanted it to be useful if audio buses were different in a project it was imported to, and I wanted to easily update the button press and volume confirmation sounds in a project in one place.
When I first made a global script, I made it a singleton with static variables and methods like I would in any other language. Then I learned that Autoloads are the way to go in Godot. Then, I learned that you should always inherit your script from Node, and create a scene that it’s attached to, and use that scene as your Autoload. Also note, you don’t want a class_name in your script. That goes in the project settings. Though I do recommend you put the name of the class in a comment at the top of your script for when you’re debugging and wondering what script you’re in.
Using a scene as an Autoload not only allows you to export variables, but as you can see in the example, you can attach other things to it. In my case, three differently configured AudioStreamPlayers.
It also allows you to use signals without hacks. (There’s a thread or two on here somewhere talking about how to send a static signal, but don’t do that. Do this instead.) You can treat it as you would a signal from a static object. So for example that same Autoload has this signal:
signal volume_changed(audio_bus: String, new_value: float)
And I can call it anywhere in my project just so:
Sound.volume_changed.emit("Music", 1.0)
Then I can watch for it anywhere else in my project like this:
func _ready() -> void:
Sound.volume_changed.connect(_on_volume_changed)
func _on_volume_changed(incoming_bus: String, value: float):
if incoming_bus == bus:
text = str(round(value * 100))