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

Signal is not created in specified object #97221

Closed
nezvers opened this issue Sep 20, 2024 · 9 comments · Fixed by #97357
Closed

Signal is not created in specified object #97221

nezvers opened this issue Sep 20, 2024 · 9 comments · Fixed by #97357

Comments

@nezvers
Copy link

nezvers commented Sep 20, 2024

Tested versions

  • reproducible in v4.3.stable.official [77dcf97]

System information

Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2070 SUPER (NVIDIA; 31.0.15.5186) - Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 Threads)

Issue description

Documentation says:

Signal Signal(object: Object, signal: StringName)

Creates a new Signal named signal in the specified object.

But testing with this

extends Node

func _ready()->void:
	Signal(self, "damaged") # <----
	var signal_list:Array[Dictionary] = get_signal_list()
	for dict:Dictionary in signal_list:
		print(dict.name)

Results:

ready
renamed
tree_entered
tree_exiting
tree_exited
child_entered_tree
child_exiting_tree
child_order_changed
replacing_by
editor_description_changed
script_changed
property_list_changed
??? NO DAMAGED SIGNAL ???

I know that function returns a Signal, that seems to be bound to the object (using print()). But it's expected to be present in the signal list and accessed like a normal Signal.
If it's not part of objects signals, then what's the point to have an object reference as a parameter to Signal(object, signal_name)?
Signal() without provided parameters is useless, because it doesn't work when created in Array[Signal].
In result Signal construction is a bag of mixed signals.

Steps to reproduce

  • use function Signal(self, "damaged") to create a new signal for the object
  • check if signal is created with get_signal_list()

Minimal reproduction project (MRP)

signal_not_created.zip

@AThousandShips
Copy link
Member

AThousandShips commented Sep 20, 2024

The documentation is incorrect, or rather unclear, this is not intended to work that way, the description should be improved instead

It should say "Creates a signal object referencing a signal named signal in the specified object."

@nezvers
Copy link
Author

nezvers commented Sep 20, 2024

What's the deal with empty Signal( )? It doesn't work for me.
Constructs an empty Signal with no object nor signal name bound.
I don't care about Object and name, those are useless if only assignable to a variable (same as Signal(object, signal_name) ).

@AThousandShips
Copy link
Member

AThousandShips commented Sep 20, 2024

What do you mean? You might be confused here, Signal isn't a signal in an object, it's a reference to a signal, a link to it if you will, as it says at the top, it is just a variable allowing you to do things more easily, my_signal.emit is just shorthand for my_object.emit

@nezvers
Copy link
Author

nezvers commented Sep 20, 2024

Ok, then why Signal( ) exists?
There are no options to make it usable later.

@AThousandShips
Copy link
Member

AThousandShips commented Sep 20, 2024

Because you can have a static typed variable that needs to start out empty:

var signal_to_use : Signal
if use_first:
    signal_to_use = first_signal
elif use_second:
...

signal_to_use.emit()

But this is more a support question, let's focus on the documentation issue, please discuss other things in the other community channels

@nezvers
Copy link
Author

nezvers commented Sep 20, 2024

Because you can have a static type variable that needs to start out empty:

Alright, that's a good reason. That also needs to be mentioned in documentation.
I run into that problem in several projects (Signal( ) not working).

@AThousandShips
Copy link
Member

It is mentioned:

Signals allow all connected Callables (and by extension their respective objects) to listen and react to events, without directly referencing one another. This keeps the code flexible and easier to manage.

It also says how to declare signals and that it isn't done by creating a Signal object, I don't think this is a confusion we can or need to prevent more than we already do

@Manik2607
Copy link
Contributor

I would like to contribute to this if you don't mind.
just need to change the description in doc/classes/Signal.xml file right?

@AThousandShips
Copy link
Member

Yep!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants