godot
godot copied to clipboard
Signal is not created in specified object
Tested versions
- reproducible in v4.3.stable.official [77dcf97d8]
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)
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."
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) ).
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
Ok, then why Signal( ) exists?
There are no options to make it usable later.
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
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).
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
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?
Yep!