Returning objects between C# and Godot

Godot Version

Godot 4.3

Question

Methods that are async or return a class object results in the “Invalid call. Nonexistant function ‘name’ in base” exception. I am able to call the method named “Test” but not the other two.

public bool Test(){
		return true;
	}
	
	public async Task<bool> TestAsync(){
		return true;
	}
	
	public SqlExecResult Setup(bool drop = false)
	{
		var exec = new SqlExec(_connString, (drop) ? _buildTables : _dropTables + _buildTables);

		return exec.ExecNQSP();
	}

Below is my code to test each method

func _ready() -> void:
	var my_csharp_script = load("res://SQL/Dao/GameDao.cs")
	var myTestObj = my_csharp_script.new()
	var result1 = myTestObj.Test()
	var result2 = myTestObj.TestAsync()
	var result3 = myTestObj.Setup()

I believe you need to use a variant type as the return:

Is it possible to do that with a c# class I created?

Within the class you should be able to use whatever.

Are you saying that I can pass back my SqlExecResult object as the method returns to GDScript? The link you gave appears to list specific Godot classes that can be returned. Could you explain what I would do to be able to call my Setup method in GDscript and return my SqlExecResult?

No I’m saying you can pass that within c#

Gdscript doesn’t recognize c# classes. However, Gdscript can access a csharp Node’s properties. However, properties must be of a variant type. Below, int and string are fine. But public MY_CSHARP_CLASS MY_CLASS is NOT fine.

MyCsharpNode.cs

using Godot;
using System;
public class MY_CSHARP_CLASS {
	public int MY_CLASS_NUM = 999;
}
[GlobalClass]
public partial class MyCsharpNode:Node {
	public int MY_NUM = 99;
	public string MY_STR = "Hello, world";
	public MY_CSHARP_CLASS MY_CLASS = new MY_CSHARP_CLASS();
}

MyGdscript.gd

extends Node

func _ready():
	# this works
	print($"/root/1/Csharp".MY_NUM)
	
	# this also works
	print($"/root/1/Csharp".MY_STR)
	
	# doesn't work
	print($"/root/1/Csharp".MY_CSHARP_CLASS);