godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.17k stars 98 forks source link

Allow exporting generic types which inherit from resources / nodes (C#) #10896

Open MatthiasBae opened 1 month ago

MatthiasBae commented 1 month ago

Describe the project you are working on

I am working on a 2D game and doing procedural generation of 2D maps. This includes placing entities like stones, trees or similar

Describe the problem or limitation you are having in your project

To have a clearer strucure and not have a single huge config class for different entities, I would like to abstract the config class so that I have one config class per entity which inherits from the base config class.

To use the inherited config in an actual class, it has to be a generic class which includes the generic type as attribute. It is not possible at the moment to export generics.

image

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Allowing exporting the generic attribute would improve the code structure a lot and you do not have to rely on a single giant config class for all entities.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

It should look like this in the inspector:

image

Clicking on on the config attribute in the inspector would only show the generic type resources (in this case EntityStoneConfig)

image

Use case example

EntityConfig Base class

image

EntityConfig Stone class

image

EntityConfig Tree class

image

Entity Base class

image

Entity Tree class (this will be added to the Nodes)

image

Entity Stone class (this will be added to the Nodes)

image

If this enhancement will not be used often, can it be worked around with a few lines of script?

There is no known workaround at the moment

Is there a reason why this should be core and not an add-on in the asset library?

This should be core because C# is at the moment also a core language in Godot which has some small limitations. With allowing generic classes / nodes in the last year this is a case which has been missing since.

raulsntos commented 1 month ago

Sounds like a duplicate of one or both of these: