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

CSharp static methods not visible/accessible #79896

Closed
MikeSchulze opened this issue Jul 25, 2023 · 3 comments · Fixed by #81783
Closed

CSharp static methods not visible/accessible #79896

MikeSchulze opened this issue Jul 25, 2023 · 3 comments · Fixed by #81783

Comments

@MikeSchulze
Copy link

MikeSchulze commented Jul 25, 2023

Godot version

v4.1.stable.mono.official [9704596]

System information

Windows 10

Issue description

I want to load an external class that was loaded into the project via nuget package and access the static methods provided.
Accessing the static methods does not work, the methods are not found.
I am using the same approach I used in Godot3, but it seems to be broken in Godot4.

Steps to reproduce

I build a simple test project with a given c# class containig two methods.

public partial class TestClass : Node
{
	
	public static string Foo() {
		return "foo";
	} 
	
	public string Bar() {
		return "bar";
	} 
}

And load them via const TestClass = preload("res://TestClass.cs")
i can access the method Bar() but the static method Foo is not accessible.

The only way around this problem is to write a wrapper method to call the static method it contains, but this is extremely inconvenient.

// GdUnit4 c# API wrapper
public partial class GdUnit4MonoApi : GdUnit4.GdUnit4MonoAPI
{
	public bool _IsTestSuite(string classPath) {
		return GdUnit4.GdUnit4MonoAPI.IsTestSuite(classPath);
	}
}

Load the attached example to reproduce.

Minimal reproduction project

csharp-statics.zip

@MikeSchulze
Copy link
Author

MikeSchulze commented Jul 27, 2023

@RedworkDE why this is maked as enhancement?
static methods was supported on Godot3 and is a regression.

I saw also issues by loading external c# classes public methods are not found.
I will prepare an small example project in the next days to show the regression between Godot3 and Godot4

@RedworkDE
Copy link
Member

The line between bug and enhancement is often pretty vague, in this case I picked enhancement because as far as I can tell this isn't an issue with any existing code, instead the code that is required for this to work doesn't exist yet at all.

@MikeSchulze
Copy link
Author

it is a problem i used it on Godot3, and its broken on Godot4
https://github.com/MikeSchulze/gdUnit3/blob/master/addons/gdUnit3/src/mono/GdUnit3MonoAPI.cs
https://github.com/MikeSchulze/gdUnit3Mono/blob/master/src/GdUnit3MonoAPI.cs

Same code with static methods is not working anymore on Godot4

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

Successfully merging a pull request may close this issue.

4 participants