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

Objects should send themselves as first argument to any signal #7166

Open
Shadowblitz16 opened this issue Jun 27, 2023 · 3 comments · May be fixed by godotengine/godot#60143
Open

Objects should send themselves as first argument to any signal #7166

Shadowblitz16 opened this issue Jun 27, 2023 · 3 comments · May be fixed by godotengine/godot#60143
Labels
breaks compat Proposal will inevitably break compatibility topic:core

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Jun 27, 2023

Describe the project you are working on

A spaceship game

Describe the problem or limitation you are having in your project

I need a way to get the object the signal happened on without having to manually bind a nodepath each time

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

signals would just be redefined as signal(args...) to signal(sender:<SelfObjectTypeHere>, args...)
they would be statically typed it the background but using the static typing in the callback signature would be optional

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

# Node

signal do_something

do_something.connect(_on_do_something)
do_something.emit()

# sender is automatically passed in
func _on_do_something(sender:Node)->void:
  pass
# Node2D

signal do_something
do_something.connect(_on_do_something)
do_something.connect(_on_do_something2)
do_something.emit()

# sender is automatically passed in
func _on_do_something(sender:Node2D)->void:
  pass

# error! signal must accept first argument as type self
func _on_do_something2()->void:
  pass

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

It can be worked around but it requires awkwardly binding a additional argument when signals should already carry that info.

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

It improves the godot messaging system

@Shadowblitz16 Shadowblitz16 changed the title Nodes should send themselves as first argument to any signal Objects should send themselves as first argument to any signal Jun 27, 2023
@Calinou
Copy link
Member

Calinou commented Jun 27, 2023

Doing this by default would break compatibility with existing projects, as the number of arguments would change for all signal functions (and you can't have a mismatch).

@Calinou Calinou added the breaks compat Proposal will inevitably break compatibility label Jun 27, 2023
@YuriSizov
Copy link
Contributor

It can be worked around but it requires awkwardly binding a additional argument when signals should already carry that info.

In Godot signals normally don't carry any information that you can get otherwise. Binding the node that you already have a reference to is the correct and expected way. Same goes for any other information that you can determine at connect or at emit time without extra arguments. So your suggestion goes against the design principle of the engine.

@KoBeWi
Copy link
Member

KoBeWi commented Jun 27, 2023

godotengine/godot#60143 implements this as optional flag, which is much better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks compat Proposal will inevitably break compatibility topic:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants