godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.99k stars 21.17k forks source link

C# Export on List not possible anymore. #70298

Open Vukbo opened 1 year ago

Vukbo commented 1 year ago

Godot version

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

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 commented 1 year ago

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 commented 1 year ago

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 (https://github.com/godotengine/godot/pull/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 (3123be2384c14f7dd156b1cc2d53d822002b837a) 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 commented 1 year ago

Will C# Lists be supported in the future again?

CookieBadger commented 1 year ago

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 commented 1 year ago

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.

agree

Calinou commented 1 year ago

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

tehKaiN commented 2 months ago

I'm having a similar issue and trying to come up with some generic solution for this problem. My vision of the fix is not crystal-clear, and I haven't dabbled too deep in godotsharp technicalities, hence I'm not writing a proposal yet, but I'd like to test the waters first and ask for some opinions: https://github.com/godotengine/godot-proposals/discussions/10709