-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Implement exporting struct variables in C# #438
Comments
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
this should be serialized as a value type so for example if you had something like so..
MyNode's MyStruct property should be serialized in such a way that its not a drag and dropable item but instead is a expandable category similar to what unity does. |
@Shadowblitz16 I agree. My primary reasoning for recommending using structs is that they have a far lower instantiation cost (when not boxed) as well as lower individual access (reducing the amount of pointer chases necessary to access memory). |
Use Resource and this addon https://github.com/wmigor/godot-mono-custom-resource-register |
Interestingly godot already DOES support struct exporting for some specific struct types like Vector2, Vector3 including exporting Arrays of those struct types: I think a good first start towards this is to limit the scope of this to immediate primitive typed fields in the struct like Vector2 does as well. (Only int and int as exported class fields). Could someone point me at the code that does handle the Vector2 exporting? |
It's been a while since I went through it, but there is a bunch of C# marshalling code that |
I was also thinking of working on addon to see if it can be achieved by adding Custom C# Attribute, to marshal the struct by myself then translate them into current ExportGroup behaviour. However, those code to read C# Attribute is in |
I'm currently facing this exact struggle wth converting my game scriptables from my unity project. |
Same exact problem here. While porting I had converted my structs and serialized classes into classes that derive from Resource, but quickly realized that it does not work how I had hoped... |
This likely depends on #7329 being implemented first, as exposing structs to the inspector requires the presence of a core struct type in the first place. |
Gonna copy my problem as well (from another issue). Currently I have no idea how to solve that. Ran into this issue myself. I can't even use the ExportGroup attribute here, as I need to have multiple modifier and not just one. I would love to just use a C# struct for that and be able to export it, as I currently don't know how to do it otherwise. Again using a variety of Resources for that is out of the option, as this would result in hundreds of resources for something which should not be a resource at all. To give more insight. |
I can reach literally needed behaviour with public partial class MyNode : Node
{
[ExportGroup("Coordinates")]
[Export] private int Colum { get; set; }
[Export] private int Row { get; set; }
public Coordinates Coordinates => new(Column, Row);
} (yes I know about But it would be not cool to just copy-paste these lines every time i need to provide this thing |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This is exactly my biggest pain point at present. Inheritance from "resource" is too bloated for me. I see that this issue was put forward five years ago. I wonder if there has been any progress or if there is something like a planned roadmap? |
This still needs a struct type to be exposed to GDScript first, as mentioned above: #438 (comment) There was a pull request implementing structs but it seems to be on hold for now: godotengine/godot#82198 Therefore, I don't know when this will be implemented. |
Would there be any possibility of not adding structs to GDScript as a prerequisite before this? This feature would be extremely useful to me too, even if the GDScript interop wasn't there at first. GDScript seems fine as a simpler introduction to coding for newbies, but for more substantial projects C# is by far the stronger choice at the moment (at least in my opinion), and I think this feature would probably be much more important to the latter kind of use case than the former. And so maybe it would be okay for the GDScript implementation to come after? |
The issue is that the rest of Godot needs a struct type to be exposed before it can effectively be used within the editor. If you want to be able to export a struct type, it needs to be editable within the inspector, usable as a method parameter and a return type (so it appears in the class reference correctly). At this point, you've done a big chunk of the work required to implement structs in GDScript, so you might as well go all the way there 🙂 |
Describe the project you are working on:
Top-down shooter with a heavily reliance on data-driven design in character composition.
Describe the problem or limitation you are having in your project:
I have a
Resource
namedRace
which defines species data about the visual and physical composition about a creature, which is then taken and applied to a genericRigidBody
-derivedActor
class.I am using
struct
s to group data together that is related, in order to avoid managing multiple arrays of parallel values in the editor's inspector UI. In this system,struct
s are preferred overclass
instances due to their lighter footprint and lack of need for polymorphism.Describe how this feature / enhancement will help you overcome this problem or limitation:
This approach is not currently supported as Godot cannot export
struct
members into the inspector UI.I am blanking on a workaround for this and believe that this is something that the engine should support in some way.
Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
Describe implementation detail for your proposal (in code), if possible:
A sub-grouping that appears in the editor's inspector view containing the exported properties of the
struct
.If this enhancement will not be used often, can it be worked around with a few lines of script?:
This enhancement is purely additive and should not impact existing code in any way.
Is there a reason why this should be core and not an add-on in the asset library?:
It involves integration into the engine's editor UI and most likely its Mono / editor bindings.
The text was updated successfully, but these errors were encountered: