How to create a global var in an addon?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By chanon

How can I make a global that is accessible within an addon without having to use Autloads?

:bust_in_silhouette: Reply From: Aaron Franke

You use AutoLoads to have global vars. There is no other way.

You can also use ProjectSettings to create global variables of sorts, but it’s not possible to make use of static typing with them.

# The value can be any Variant.
ProjectSettings.set_setting("my/custom_value", "Hello world")
# Prints "Hello world".
print(ProjectSettings.get_setting("my/custom_value"))

Calinou | 2020-07-16 09:57