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#: Allow exporting custom types (System.Object class or struct) #997

Open
Flavelius opened this issue Jun 2, 2020 · 5 comments
Open

C#: Allow exporting custom types (System.Object class or struct) #997

Flavelius opened this issue Jun 2, 2020 · 5 comments
Assignees

Comments

@Flavelius
Copy link

Flavelius commented Jun 2, 2020

Describe the project you are working on:
Just looking forward to using godot

Describe the problem or limitation you are having in your project:
Currently, exporting a field with type of a custom class or struct just doesn't work, godot can't seem to handle it.
The output prints 'unknown exported member type: [xyz]'
I tried to find workarounds, but just found more undesired behaviour.
First i tried using GetPropertyList to maybe add an editorplugin to draw them myself. But the return value doesn't include the scripts values. This also ruled out serializing the custom fields value into another field that godot can serialize (unity-like workaround), plus overriding _GetPropertyList also doesn't work correctly (setting usage for the property to NoEditor does not hide the property, desired equivalent is unity's [SerializeField, HideInEditor] combination).
Also, inheriting from ISerializationListener, which sounded promising (like unity's ISerializationCallback) did nothing, the callbacks didn't get invoked, but maybe that's even by design, although still limiting.
So there seems to be no feasible workaround.
The problem is that in c# it's quite common and often even necessary to group data via objects (or structs) for serialization, messaging etc. . And property editors should aid in editing those too (like in other popular engines)

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Implementing serialization/editing/[Export]ing custom classes will benefit every c# developer.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
It could work like regular property editing when presented to the user. Objects could be foldouts of properties when displayed in the inspector.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
It doesn't seem to be possible to be worked around as described above.

Is there a reason why this should be core and not an add-on in the asset library?:
This seems to requires changes in the engine.

@hnOsmium0001
Copy link

Related to #438

@wmigor
Copy link

wmigor commented Mar 27, 2021

Use this addon https://github.com/wmigor/godot-mono-custom-resource-register

@Flavelius
Copy link
Author

Use this addon https://github.com/wmigor/godot-mono-custom-resource-register

Thx, but your addon is not related to the proposal. It just assumes that resources that godot can already export have scripts contained in predefined folders to register those to godot's property editor dropdown. This proposal is for exporting clr types like struct, that godot currently doesn't handle.

@RobProductions
Copy link

This is a pretty huge pain point for me right now as I'd love to be able to group my exported fields through subclasses the same way I did in Unity. I'm trying to get debug visibility on more complicated fields that are mainly driven by runtime operations, and the only way I found to do that is to keep them at the class level instead of nesting them which was really making the Inspector ugly. I've realized that I could probably use Resources to get similar grouping behavior in the Inspector but when I tried it out it seems to have a bunch of caveats such as unneeded file clutter, tedious to set up, and complications setting the data at runtime.

I now discovered that [ExportGroup] allows for grouping similar to how I would normally use subclasses, so that's pretty awesome! But it's still not truly ideal for certain use cases; say I want to quickly grab a certain subset of fields for creating a save file in code, I would like to be able to just read a subclass instance that holds the needed data (so I can serialize the whole object at once). I used to organize my entities that way for this purpose, but now I would have to parse through all of the fields one by one to get the same behavior. There could be plenty of other use cases as well for wanting to deal with arbitrary objects/subclasses and it would be really nice to see them in the Inspector. I will definitely need to do some research here to see what it would take to support this in the editor.

@Drommedhar
Copy link

Drommedhar commented Dec 31, 2023

Ran into this issue myself.
In my case I want to subset an array of modifiers inside a resource to a class/struct. These contain always the same properties, but can be filled with different values/settings. In Unity I would just create a ScriptableObject class for these modifiers, add these as an array to my other ScriptableObject and was able to add/remove and change each value directly on the object itself.
In Godot this would require me to create an resource for each modifier, link it (which is a pain with the big dropout for even creating new resources inside a resource) etc. This is not really usable.

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.

EDIT:
To give more insight.
I have an Item class (as a resource) which has AttributeModifiers (which would alter player or enemy attributes). This might include add or remove health etc. These are driven by an enum, which would tell me whic attribute to manipulate, what to do with it and so on.

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

7 participants