godot icon indicating copy to clipboard operation
godot copied to clipboard

Signal is not created in specified object

Open nezvers opened this issue 1 year ago • 9 comments

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)

signal_not_created.zip

nezvers avatar Sep 20 '24 07:09 nezvers

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."

AThousandShips avatar Sep 20 '24 09:09 AThousandShips

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) ).

nezvers avatar Sep 20 '24 13:09 nezvers

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

AThousandShips avatar Sep 20 '24 13:09 AThousandShips

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

nezvers avatar Sep 20 '24 13:09 nezvers

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

AThousandShips avatar Sep 20 '24 13:09 AThousandShips

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).

nezvers avatar Sep 20 '24 13:09 nezvers

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

AThousandShips avatar Sep 20 '24 13:09 AThousandShips

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?

Manik2607 avatar Sep 22 '24 17:09 Manik2607

Yep!

AThousandShips avatar Sep 22 '24 17:09 AThousandShips