All Questions

Community

S
Azraelle Studios

uses for autoload

From the warning below the lesson I would assume that if, for example, you are creating an RPG with a lot of quests it would be more efficient to use a save load system. By that I mean for saving data regarding quest completion/dialogue choice data.
  • You could, the danger comes from calling into the autoloaded node from many scenes, as it makes debugging your code harder and harder.

    The issue with singletons is that you can use them anywhere in your code, like anything global, and you could introduce a bug anywhere. That is, if the autoloaded node exposes functions that change data.

    For a save and load system, you can use one with great care, allowing only one node to use the save system, or working with a signal that triggers the autoload. But in that case, you might as well have a SaveAndLoad object in your scene, that belongs to a top-level Game node.

    In Godot, one way to structure your game is to not use get_tree().change_scene() to change scenes, but to instead have a node that frees e.g. the level and replaces it in a single scene. This allows you to keep some nodes that aren't global, like a Game node, a LevelLoader, etc. We have that kind of setup in the 2D platformer on GitHub: https://github.com/GDQuest/godot-platformer-2d

    With that kind of scene structure, you can work without singletons.