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

Static signals #10680

Closed
AdriaandeJongh opened this issue Sep 7, 2024 · 3 comments
Closed

Static signals #10680

AdriaandeJongh opened this issue Sep 7, 2024 · 3 comments

Comments

@AdriaandeJongh
Copy link

AdriaandeJongh commented Sep 7, 2024

Describe the project you are working on

A tower defense game called Rift Riff and soon a sequel to my indie hit game Hidden Folks.

Describe the problem or limitation you are having in your project

I use signals on singletons quite a lot:

GameManager.instance.some_signal

The (albeit minor) downside of this approach is that this requires the singleton object to be initialized and assigned. I rarely have issues with this particular pattern, but when I do it's usually when I run into tricky initialization order issues.

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

It would be awesome if I could define static signals like so:

class_name GameManager
extends Node

static signal some_signal

func _ready():
    some_signal.emit()

... allowing this signal to be accessible from anywhere like so – even from _init() functions in other classes before any singletons associated with the class in question have been initialized and assigned:

GameManager.some_signal.connect(my_function)

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

As per usual in my proposals (sorry, I'm 'just' a game dev!) I don't know enough about the engine's inner workings to say anything meaningful here.

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

I could simply continue to use the signal through my singletons.

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

Not sure if it's core or GDScript, but this is part of either of those.

@tetrapod00
Copy link

I wonder if this would be helpful for implementing the common events bus pattern (https://www.gdquest.com/tutorial/godot/design-patterns/event-bus-singleton/)?

@passivestar
Copy link

Duplicate of #6851

@dalexeev
Copy link
Member

dalexeev commented Sep 9, 2024

@dalexeev dalexeev closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2024
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