godotengine / godotengine/godot

[.Net / GDScript Interop] Cannot Call GDScript-Lambda-Backed `Callable` in C#

Open
#97,358 8 comments 0 reactions 0 assignees View on GitHub
bug confirmed topic:core topic:dotnet topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

v4.3.stable.mono.official [77dcf97d8]

### System information

Godot v4.3.stable.mono - Windows 10.0.17763 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 Ti (NVIDIA; 32.0.15.6109) - AMD Ryzen 9 5900X 12-Core Processor (24 Threads)

### Issue description

This is a niche use case, but we should document it if it's not supported.

In C# script, when trying to `Call()` a `Callable` that is backed by a `GDScript` `Lambda Expression`, Godot will produce the following error instead of actually making the call.

```
E 0:00:00:0894 main.gd:4 @ _ready(): Attempt to call callable 'null::null' on a null instance.
/root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:160 @ void Godot.NativeInterop.ExceptionUtils.DebugCheckCallError(Godot.NativeInterop.godot_callable&, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error)
main.gd:4 @ _ready()
```

### Steps to reproduce

1. Create a C# Godot Project.
2. Create `main.gd`.
3. Create a scene, attach the `main.gd` to the root node, and save it to a file.
4. Create `Helper.cs`.
5. Run the project.

### Minimal reproduction project (MRP)

**main.gd**

```gdscript
extends Node

func _ready():
Helper.new().CallCallable(func(): print("Hello World"));
```

**Helper.cs**

```csharp
using Godot;

[GlobalClass]
public partial class Helper : Node
{
public void CallCallable(Callable callable) => callable.Call();
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the interop failure using main.gd and Helper.cs, especially Helper.CallCallable and the GDScript lambda passed to it. Read the reported call-error handling in modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs. Done means determining whether this Callable combination should work and documenting the supported behavior or confirming the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.