Problem with tween_completed signal on C#

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

Hello,

I’ve been toying around with Godot and C#, but i’ve been struggling to trigger a method when the tween is completed, you see i have the following code:

on CoinArea.cs

    public void OnCoinTweenTweenCompleted(){
    GD.Print("tweencompleted!");
    QueueFree();

}

Then I have connected the tween signal to my CoinArea node, set create function to false so it doesn’t create the function since it is already created and then i paste the name: OnCoinTweenTweenCompleted.

Then I test the main scene, the tween ‘works’ but the method OnCoindTweenTweenCompleted never gets triggered, and the editor i get the following:

0:00:06:0011 - Error calling method from signal ‘tween_completed’:
‘Area2D(CoinArea.cs)::OnCoinTweenTweenCompleted’: Method not found.
---------- Tipo:Error Descripción: Tiempo: 0:00:06:0011 C Error: Error calling method from signal ‘tween_completed’:
‘Area2D(CoinArea.cs)::OnCoinTweenTweenCompleted’: Method not found. C
Fuente: core/object.cpp:1202 C Función: emit_signal

And I’m a bit confussed because i’ve already used other signals using pre-existing methods and well they just work, it does seem like it is trying to fetch the method, but is not able to get it, yet the method is there, can someone assist to point out what have i done wrong?
Regards!

:bust_in_silhouette: Reply From: -darkwing-

As a work around i’ve donde this (is a lil dirty on the coding style end):

    public async void PickUp(){
    Monitoring=false;
    ((Tween)GetNode("CoinTween")).Start();
    await ToSignal(((Tween)GetNode("CoinTween")),"tween_completed");
    OnCoinTweenTweenCompleted();
    //GD.Print( ((Tween)GetNode("CoinTween")).Start() );
    //QueueFree();
}

This is the method that starts the tween, instead of starting the tween and trusting the inspector to wire up the signal, i made the method to wait for the tween to emit the signal (provided that the signal is still emitted,but is not able to call the method i need) and well the method is just going to wait to receive the signal from when the tween is done and then trigger the function it needs to be triggered. This “works” but just because what i’m trying to do is on the simple end, does anybody know if what i’m facing is a bug? Should i try to report it on the bug tracker?

:bust_in_silhouette: Reply From: Konstantin Kitmanov

I know this is old post, but I stumbled upon the same problem. After some fiddling I found out that the method which you connect to signal should have the same signature as signal in docs. In case of tween_completed, it should look like this:

public void OnTweenCompleted(Godot.Object obj, NodePath key)
{
	// do stuff
}

Hope that helps somebody.

This was exactly my problem and the solution. The docs mention this in passing but it was easy to overlook. Thank you!

seratoninronin | 2020-02-25 20:10