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

GDScript function isn't called from C# when parameter types don't match #83765

Closed
DragonAxe opened this issue Oct 22, 2023 · 2 comments
Closed

Comments

@DragonAxe
Copy link

DragonAxe commented Oct 22, 2023

Godot version

v4.1.2.stable.mono.official [399c9dc]

System information

Godot v4.1.2.stable.mono - Manjaro Linux #1 SMP PREEMPT Sat Sep 23 10:10:02 UTC 2023 - Wayland - Vulkan (Forward+) - integrated Intel(R) UHD Graphics 620 (KBL GT2) () - Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz (8 Threads)

Issue description

When calling a GDScript function from C# (using the .Call function), if the type of a given parameter doesn't match the GDScript type annotation, then the GDScript function is never called and no errors or warnings are given. Not having a runtime error/warning makes it difficult to track down bugs caused by mismatched types across the GDScript/C# boundary.

Update: Just tested by calling a GDScript function that doesn't exist (e.g. .Call("non_existent_function")), and the behavior is identical to calling a function with miss-matched parameter types, i.e. no error or warning is given.

Steps to reproduce

Here is an example:

Create a new C# project.
Create a new Node2D scene.
Attach a new C# script to the Node2D with the following contents (let's call it Main.cs):

using Godot;
public partial class Main : Node2D
{
    public override void _Ready()
    {
        GD.Print("Before GDScript call.");
        GetNode("/root/Singleton").Call("gdscript_function", <<PLACE VALUE HERE>>);
    }
}

Create singleton.gd with the following contents and add it to the list of project autoloads:

extends Node
func gdscript_function(player_name: String):
    print("Hello world says " + player_name + "!")

If <<PLACE VALUE HERE>> is the string "Bill", the output is as expected:

Before GDScript call.
Hello world says Bill!

If <<PLACE VALUE HERE>> is not a string, 1234, the output is not as expected:

Before GDScript call.

Expected output:

Before GDScript call.
Error: Function `gdscript_function` was given a value of type `int`, but `String` was expected.

Everything works as expected if I modify singleton.gd to remove the type annotation (and cast player_name to a string to avoid Invalid operands 'String' and 'int' in operator '+'.):

extends Node
func gdscript_function(player_name):
    print("Hello world says " + str(player_name) + "!")

Minimal reproduction project

godot_project.zip

@raulsntos
Copy link
Member

I think this was fixed by #79249. Can you try reproducing in Godot 4.2 beta 2?

@DragonAxe
Copy link
Author

Fixed in Godot 4.2 beta 2!

Thank you @raulsntos for finding the associated commit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants