godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Add Autoloads to the Scene tree for easier signal connection management #4993

Open Flynsarmy opened 2 years ago

Flynsarmy commented 2 years ago

Describe the project you are working on

I have an AudioManager, LevelManager, global Event bus, UnlockablesManager all autoloaded. Some of these (namely the global Event bus) have a lot of signals defined. These signals are connected to and used by a large number of scenes in my game.

Describe the problem or limitation you are having in your project

Not so much a limitation as a difficulty. Global event busses are very commonly used pattern in Godot projects however their major downside is that it can be difficult to tell what they're connecting to and all connections must be manually made in code.

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

I propose adding a collapsible list of autoloads to the top of the Scene tree. These nodes could be clicked on and signal connections made in the same way you currently can with any child node of your scene.

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

I propose adding a collapsible list of autoloads to the Scene tree like so: GlobalEventBus

Signals from these autoloads would work identically to signals from any node in your tree. You click the autoload class, go to the Node tab and connect a signal. An autoloads Node tab would only show connections for the currently loaded Scene.

Scene trees can become quite full in more complex scenes and on larger projects there can be a lot of autoloads, so for this reason I've suggested a collapsible list to easily get the new rows out of sight.

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

This proposal is commonly worked around with the caveat that it's not quite as intuitive or easy to use as the GUI-based signal system.

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

I'm not familiar enough with the engine to know if it's possible for this to be added with an add-on. I believe the feature should be core because it leverages existing functionality in a new way to make a common use-case more intuitive.

YuriSizov commented 2 years ago

See also https://github.com/godotengine/godot-proposals/issues/1694

mieldepoche commented 2 years ago

I had a proposal idea about having a "root scene" dock displaying a scene view where the root is a Viewport (or Window in 4.0) and adding children to it would register autoloads without having to go through the dedicated interface. These nodes would interact with the inspector like regular nodes so they could all be configured this way (if they export properties for example). This would have provided root viewport configuration in the usual inspector and a clear view of what the root actually is and where autoloads live in the tree.

Maybe some of these ideas can be salvaged.

me2beats commented 2 years ago

I like the idea to see singletons in the SceneTreeEditor, I also imagine you can work with singletons almost just like with a regular node, like change properties in Inspector especially exported properties (export var). This could make singletons more reusable — you can use a singleton in other projects without changing the script but still tweak something using export vars

me2beats commented 2 years ago

One thing I am worry about is that in the proposed screenshots it kinda looks like singletons belong to scenes, this can be confusing for new users

thornySoap commented 1 year ago

(#6927) Another advantage would be that Autoloads could be directly referenced to nodes that have a Node-property exported.

jinyangcruise commented 6 months ago

I like the idea to see singletons in the SceneTreeEditor, I also imagine we can see singletons in the ConnectDialog. something like this:

image
shak2 commented 3 months ago

I like this idea.

But also, add a tick box in project settings to do this. Some people don't use autoloads regularly and it would bloat their trees.

JimArtificer commented 3 months ago

The most interesting application of this to me is the enhancement to the "Connect a Signal" dialog. Being able to connect to an event bus or another type of autoload singleton would save time and reduce the need for small scripts.