The game has a time system. Now it is implemented as follows: there is a static TimeManager class, which contains a static DateTime variable and a method GetTime to get string representation of the DateTime var. There is also a TimeHandler node that I want to add to autoload so that all other handlers can connect to its signals. Or to implement Signals singleton pattern...
I have other similar systems. Two questions:
- Is this static class necessary, or should the data be stuffed into the node for autoload?
- If in a node, then it will load in all scenes. And I need time for each level to load my own. And this year's work is not needed in the menu.
What is the best thing to do?
So you have
class_name TimeManager ... static var DateTime static func GetTime()
Then you want
TimeHandlernode because you can't use signals on that
TimeManagerclass you autoload it. So what's the difference between static and autoload in Godot? The main difference between
autoloadis where it's located. Static located in the class itself, autoload is located in the SceneTree giving you access to all the nodes in your scene.
- Static class isn't necessary, nor the autoloads. Pick whatever make sense to you.
- Yes, if you set
TimeHandleras an autoload, it will be loaded on all scenes anywhere you go. So this might not be ideal if you don't always need
Hard choice. Ditching TimeManager statics, and just shove everything in an Autoload node might be the easiest.