Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to create autoload from script (without using the project settings) #5143

Closed
Chaosus opened this issue Aug 11, 2022 · 6 comments

Comments

@Chaosus
Copy link
Member

Chaosus commented Aug 11, 2022

Describe the project you are working on

Describe the problem or limitation you are having in your project

This is not a limitation - just an impovement.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The idea is to allow user creating autoload from script rather than from project setting (for the sake of comfortability and uniformity).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The following code would automatically make autoload Global for the script:

global
extends Node
class_name Global

class_name is mandatory for such scripts to allow use it in other scripts (but may be omitted if it's self-contained).

If this enhancement will not be used often, can it be worked around with a few lines of script?

No

Is there a reason why this should be core and not an add-on in the asset library?

It's a core GDScript change

@SilencedPerson
Copy link

I would use keyword autoload or singleton.

@Chaosus Chaosus changed the title Usage of global keyword to create autoload from script (without using the project settings) Add possibility to create autoload from script (without using the project settings) Aug 11, 2022
@mieldepoche
Copy link

See also #4993.

  • you don't know in what order they are added anymore, so problems may arise if one singleton depends on another in its _ready
  • I would forbid using class_name for this since its not the same thing. Also autoloaded scenes/scripts are not singleton since you can manually instantiate them however you want, so I'd use autoload instead of singleton:
extends Node
autoload Global

Also while this has the benefit of translating naturally from one project to another without further setup, I'm curious how often one would have to add a singleton for it to become that tedious.
I you really have that many scripts you can make an addon that adds every script in a directory as a singleton on startup.

@SilencedPerson
Copy link

SilencedPerson commented Aug 11, 2022

Actually, how would this interact with scripts that extend Resource?

@mieldepoche
Copy link

Actually, how would this interact with scripts that extend Resource?

I personally see no reason for this to make sense currently, so it would throw an error.

@TheDuriel
Copy link

TheDuriel commented Aug 11, 2022

I don't see how this can be useful without being able to concisely name and order your autoloads. Plus, to enable/disable these kinds of autoloads you'd have to modify the script file directly and add/remove the keyword.

The most likely scenario here I can see is, the user losing track of how and where autoloads are coming from and how they interact.

Re naming: Autoloads are not Singletons, though they share qualities. Resources are Singletons.

@Chaosus
Copy link
Member Author

Chaosus commented Aug 11, 2022

Yeah, seems like a not good idea…

@Chaosus Chaosus closed this as completed Aug 11, 2022
@Chaosus Chaosus closed this as not planned Won't fix, can't repro, duplicate, stale Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants