Could we create a class which works as a singleton but only in one scene? Sometimes I feel it is too local to make it autoloaded, but I could not find any other way. Thank you for your time!
Edit: one way to do this is using resource. Write one class
GlobalClass extending resource, which has every variable and methods you need. Then make one resource file (
.tscn) using this code, and attach it to every node which will use it (e.g. add a line
export(Resource) var global_class = global_class as GlobalClass and set the resource file in inspector). I should note that resources are passed by reference.
If I have to list Cons of this method based on my limited knowledge, I would say:
- Resources cannot receive signals directly.
- I need to remember which node is an actual global node. Otherwise, any attribute can be changed accidentally (in other words, it seems really dangerous).
I really appreciate it if you could share any other way!