0 votes

Hi all.

I had a look at Autoload, and figured it would work pretty well for things like holding High Score values, Team Names, and player-picked color values. Thing is, though, I don't exactly know how that would look, and was wondering if anyone could provide a basic example?

in Engine by (197 points)

1 Answer

+1 vote

Singletons/Autoload scripts are basically nodes that are children of the root and the same level in the hierarchy as the current scene node. They are referenced by the node's name which doesn't necessarily have to be the script's name and the variables can be accessed directly through that.

e.g. in the autoload tab

name: the_autoload    path: res://my_script.gd

my_script.gd which is the autoload script.

extends Node
var my_var = 5

Another script in the scene.

print(the_autoload.my_var)

prints 5

by (3,199 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.