0 votes

I want to add a new singleton, loaded from my server, after the game started.
I don't want to just instance a node, because I want to take advantage of the short naming.

Is it possible?

Godot version 3.2.3
in Engine by (168 points)

Do you mean you don't want to use AutoLoad?

1 Answer

0 votes

No, it's not possible. You have to set up singletons beforehand with autoload. I don't see why anyone would ever want to create them on the fly. I certainly wouldn't be in favour of Godot implementing this functionality. You have to be really careful with global variables, many coders shun them altogether and those that do use them with extreme care, as you can easily end up with spaghetti code. Making whole singletons on the fly sounds like a nightmare scenario.

"I want to take advantage of short naming" - what do you mean by this?

by (2,154 points)

The motivation is, due to Play store's extremely long review times, to be able to update the singleton code without releasing a new revision to the store.
So it's not really creating it "on the fly", but it's creating it only once, after the framework was loaded and before the game itself starts.

Short naming - instead of using a singleton it's possible to just instance a node once, and refer to it by its full path in the tree.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.