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

C# Export on List not possible anymore. #70298

Open
Vukbo opened this issue Dec 19, 2022 · 6 comments
Open

C# Export on List not possible anymore. #70298

Vukbo opened this issue Dec 19, 2022 · 6 comments

Comments

@Vukbo
Copy link

Vukbo commented Dec 19, 2022

Godot version

v4.0.beta8.mono.official [45cac42]

System information

Windows 10 Home, Intel(R) Core(TM) i5-4210H CPU @ 2.90GHz 2.90 GHz,

Issue description

In Godot 3.5 it was possible to Export C# System.Collections.Generic.Lists.
When I try doing that in the current version I get the following error:

C:\Users\Bozo\Documents\Data\Game Dev\Godot\super-beat-boy\Nodes\Activables\GravityArea.cs(21,30): The type of the exported field is not supported: 'SuperBeatBoy.GravityArea.listOfStrings'

Would like to Export my lists and use them directly, this was very helpful and streamlined to use.
So this seems like a regression to me.

Steps to reproduce

Adding following Snippet to any Code:
[Export] private System.Collections.Generic.List<String> listOfString = new System.Collections.Generic.List<string>();
This leads to following error:
C:\Users\Bozo\Documents\Data\Game Dev\Godot\ListsNotWorking\lists_not_working.cs(8,53): The type of the exported field is not supported: 'lists_not_working.listOfString'

Expected Behaviour
Being able to change the list via the Inspector like you would do with arrays. (Or like you could in Godot 3.5 with List<>())

Minimal reproduction project

C#ListsNotWorking.zip

@ghostradiogames
Copy link

ghostradiogames commented Dec 19, 2022

I can confirm that this is not working for me either, but fairly certain it was working in beta 6.

AudioManager.cs(31,34,31,46): error GD0102: The type of the exported field is not supported: 'QuestoftheWizard_CSharp.AudioManager.nodePathList'

[Export] public List<NodePath> nodePathList = new();

@raulsntos
Copy link
Member

raulsntos commented Dec 20, 2022

I doubt it was working in beta 6 because as far as I remember we removed support for .NET collections when we moved to .NET 6 (#64089), which I think was around alpha 16, and we haven't added support back.

For now you should be able to use Godot.Collections.Array as a replacement.

Keep in mind that converting between .NET collections and Godot collections is possible but can be very expensive because it requires marshaling every element.

List<string> dotnetList = new List<string>() { "a", "b", "c" };

// List to Godot array
Godot.Collections.Array<string> godotArray = new Godot.Collections.Array<string>(dotnetList);

// Godot array to List
godotArray.ToList();

The commit that removed support for .NET collections (3123be2) includes more context:

Removed support for non-Godot collections.
Support for them also relied heavily on reflection for marshaling.
Support for them will likely be re-introduced in the future, but
it will have to rely on source generators instead of reflection.

@Vukbo
Copy link
Author

Vukbo commented Dec 20, 2022

Will C# Lists be supported in the future again?

@CookieBadger
Copy link
Contributor

C# Lists and other Collections have significantly more features than Godot Arrays, and the conversion always has some code-overhead, that was not necessary in the past, so I would also greatly appreciate if exporting C# Lists became available again.

@LeonardoCruzx

This comment was marked as off-topic.

@Calinou
Copy link
Member

Calinou commented Dec 22, 2022

@LeonardoCruzx Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

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

6 participants