Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0 Beta 7] TweenCallback does not find methods with parameters #69519

Closed
valkyrienyanko opened this issue Dec 3, 2022 · 2 comments
Closed
Labels

Comments

@valkyrienyanko
Copy link

valkyrienyanko commented Dec 3, 2022

Godot version

v4.0.beta7.mono.official [0bb1e89]

System information

Windows 10, RX 6600, 10400

Issue description

TweenCallback can not find methods with parameters, although it can find methods without parameters just fine.

Steps to reproduce

The following code will reproduce the error.

public partial class Node3D : Godot.Node3D
{
    public override void _Ready()
    {
        var tween = GetTree().CreateTween();
        tween.TweenCallback(new Callable(this, nameof(Foo)));
    }

    public void Foo(int x)
    {
        GD.Print("Foo!");
    }
}

Error shown in console

E 0:00:01:0468   step: Error calling method from CallbackTweener: 'Node3D(Node3D.cs)::Foo': Method not found
  <C++ Error>    Method/function failed. Returning: false
  <C++ Source>   scene/animation/tween.cpp:624 @ step()

Minimal reproduction project

Test2.zip

@valkyrienyanko valkyrienyanko changed the title [Godot 4 Beta 7] TweenCallback does not find methods with parameters [4.0 Beta 7] TweenCallback does not find methods with parameters Dec 3, 2022
@raulsntos
Copy link
Member

I believe that's expected, tween callbacks need to be parameterless. Unfortunately, Godot doesn't support typed Callables so the compiler can't help you here, but it would be the equivalent of Action in C#.

When porting your MRP to GDScript I get this error:

ERROR: Error calling method from CallbackTweener: 'Node3D(Node3D.gd)::foo': Method expected 1 arguments, but called with 0

The error in C# is not incorrect, Foo(int) and Foo() have different signatures so they are technically different methods and C# can't find Foo(), but the error could be more user-friendly, there's an issue about this already: #35910.

In GDScript, if the method you are using has parameters you can pass them using bind as explained in the documentation:

tween.tween_callback($Sprite.set_modulate.bind(Color.red))

In C#, Callables don't have a Bind method, but you can use lambdas. The example in the documentation is outdated, it would be something like this:

tween.TweenCallback(Callable.From(() => sprite.Modulate = Colors.Red));

@valkyrienyanko
Copy link
Author

Thanks

@raulsntos raulsntos closed this as not planned Won't fix, can't repro, duplicate, stale Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants