Globals
It is a very common scenario in game development that you have some data that needs to persist across multiple scenes. Data that is part of a scene is lost when the scene is switched, so persistent data must reside somewhere outside the current scene.
Godot solves this problem with the use of AutoLoads. These are scripts or nodes that are automatically loaded in every scene. Because Godot does not support global variables, an autoload acts like a Singleton. This is a node (with attached script) that is automatically loaded in every scene. Common uses for AutoLoads include storing global data (score, player data, and so on), handling scene switching functions, or any other functions that need to be independent of the currently running ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access