Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MiPec |
Hi,
I am trying to connect signal using Connect method (because of possibility to use deferred flag).
According to the code documentation for Connect method all below commands should work in C#. Unfortunately, I am not able to make examples 2, 4 and 5 work. Am I missing something?
Ex. 2 returns method group to callable conversion error
Ex 4,5 you can’t call anything else than += and -= on an event (the signal is auto-generated as event)
var player = GetNode<Player>("Player");
player.Died += OnPlayerDied; //1
player.Connect(Player.SignalName.Died, OnPlayerDied); //2
player.Connect(Player.SignalName.Died, new Callable(this, nameof(OnPlayerDied))); //3
player.Died.Connect(OnPlayerDied); //4
player.Died.Connect(new Callable(this, nameof(OnPlayerDied))); //5
I’m on Beta12 and it seems to suggest I have to append EventHandler to each delegate to get mine to work. So this works…
[Signal] public delegate void SomethingEventHandler();
...
EmitSignal(SignalName.Something);
...
<instance>.Something += OnSomething;
But if I want to use built-in signals I have to do it as your example 3.
I’m hoping they get the documentation up-to-date soon.
Satscape | 2023-01-17 09:28