Error calling method from signal: Method not found. Why is this when connecting via an intermediate method?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zep

I have some a method as such;

public static void ConnectSignalSingleParameter(Node sourceNode, string signalName, Delegate handler)
	CustomConnectDelegates[signalName] = handler; //
	sourceNode.Connect(signalName, Instance, nameof(HandleSignal), new Array(signalName));

private void HandleSignal(object parameter, string signalName)
	if (CustomConnectDelegates.TryGetValue(signalName, out var del))

For reasons, I need this in order to connect some simple signals like OptionButton.item_selected to arbitrary handlers. However, I only get Error calling method from signal 'item_selected': 'Node(GameRoot.cs)::HandleSignal': Method not found. whenever the signal is emitted.

That method is called like so: GameRoot.ConnectSignalSingleParameter(optionButton, "item_selected", OptionHandler);

Why is this? Is there another way I can achieve this?

:bust_in_silhouette: Reply From: zep

In my case, I am using new Array(...) wrong. This constructor takes an IEnumerable, and a string just so happens to be an IEnumerable as well. Thus, Godot was an expecting a method with about 10 parameters. The fix is as follows:

sourceNode.Connect(signalName, Instance, nameof(HandleSignal), new Array { signalName });

Note the usage of new Array { signalName } rather than new Array(signalName).