Can await a c# async method in gdscript?

Godot Version

4.2.2

Question

What I wanna do is like below, which is not work.

[C#]

public async Task<int> Test()
{
        return await SomeAsyncFunc();
}

[Gdscript]

func do_test():
        var result = await C#Obj.Test()

The error is “Invalid call. Nonexistent function Test”

If it is not possible to do this, that means I can only use signal to do the async thing between c# and gdscript.

[C#]

public async Task<int> Test()
{
        int res = await SomeAsyncFunc();
        EmitSignal(SignalName.SignalTest, res);
}

[Gdscript]

func do_test():
        C#Obj.Test()
        var result = await C#Obj.SignalTest

I’ve tested, this works.

But the problem is, if there are multiple calls of do_test(), then every “await C#Obj.SignalTest” will be triggered once the first signal is emitted. I have to do more work on this to fix it.

So is there a way to await C# async method in gdscript?

gdscript cannot see c# methods and c# cannot see gdscript functions.

in the example below, Export] is used so gdscript can “see” m_is_mouse_proximity. then from gdscript is m_is_mouse_proximity == true, the signal “my_await_test_signal” is emitted.

below i [export] m_is_mouse_proximity . in c# if the distance to the mouse is < 200 pixels, m_is_mouse_proximity = true.

(unsure if this is the best way to do this but it is something)

c#

using Godot;
public partial class MyCsharp:Sprite2D {
	[Export]
	bool m_is_mouse_proximity = false;
	[Export]
	float m_distance_to_mouse = float.MaxValue;
	public override void _Process(double delta) {
		m_distance_to_mouse = GlobalPosition.DistanceTo(GetGlobalMousePosition());
		m_is_mouse_proximity = m_distance_to_mouse > 0 && m_distance_to_mouse < 200;
	}
}

gdscript:

extends Node2D

signal my_await_test_signal

func MyAwaitTest():
	await my_await_test_signal
	print ("MyAwaitTest complete")

func _ready() -> void:
	MyAwaitTest()

func _process(_a_delta: float) -> void:
	if($MySprite2D.m_is_mouse_proximity): emit_signal("my_await_test_signal")