Godot: C#/Mono [Export] custom type variable

Created on 23 Jul 2018  Â·  14Comments  Â·  Source: godotengine/godot

Currently using [Export] with a custom Class produces nothing on the inspector.

[System.Serializable]
Class CustomData
{
 [Export]
 string valueString = "";
 [Export]
 int valueInt = 0;
}

Class CustomNode : Node
{
 [Export]
 CustomData valueData;
}
archived feature proposal core

Most helpful comment

It has been a while since the last comment. Has a final decision been made on it? I'm not asking "when", but rather "if at all" :).
This feature would be extremely useful, especially if applicable to any language.

All 14 comments

Only fields and properties from the script's class can be exported. This is the way Godot works by design.

:/ so there is not even an interest on implementing such useful feature?

I agree, this is an extremely useful feature in Unity (minus the fact that Unity only serializes the base class). It allows you to edit the fields of that class in the inspector just like you would if you exported a float, int, string, etc. It also works with arrays.

I will see what can be done, but as I said this is the way Godot works by design, so I can't promise anything.

@neikeq I just think this issue should be re-opened for discussion in case someone else wants to tackle it, or for a time when you are able to look into it :)

I know you have a lot of other higher priority things on your plate regarding C#, so I wouldn't burden yourself with this right now. While I think this would be a very useful feature to have, there are still higher priority C# issues. I just don't think it's worth closing just yet.

I opened as a C#/Mono issue, but it would be useful for C++ and other
GDNative languages as well. Even GDScript maybe.

On Wed, Jul 25, 2018 at 1:09 AM Ignacio Etcheverry notifications@github.com
wrote:

Reopened #20388 https://github.com/godotengine/godot/issues/20388.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/20388#event-1751664086, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AND82kbFYDeMUrBGvLmvqM_4Y5qSKnvDks5uJ--IgaJpZM4Vbnw_
.

@vnen Do you think this is feasible to do with GDScript? It would be a useful feature.

@aaronfranke you can already do, to a certain extent, since you can make scripts derived of Resource. But for non-resource it's harder to serialize. I'm not convinced Godot should care about those things, why not use Godot Resources?

I don't think all custom type properties can be represented as resources. Sometimes, you may just want to group relevant values together and treat them as a single property.

For example, imagine you need to define rotational limitations for x, y, z axes in Euler angles. It'd be convenient if we can define a structure that contains minimum and maximum allowed angle and define such a limitation for each axis using that data type, like:

public struct RotationalLimit {

    public float Min { get; }

    public float Max { get; }
    ...
}

[Export]
public RotationalLimit X { get; set; }

[Export]
public RotationalLimit Y { get; set; }

[Export]
public RotationalLimit Z { get; set; }

Using resource is not really an option for such an use case, and implementing a similar feature without a custom type would be more cumbersome and verbose.

Currently, Godot has a limited support for grouping properties (which doesn't work in C# at the moment) and such properties cannot be nested. In comparison, it's much more convenient in Unity, since you don't have to write any custom code to use a simple struct as a property type and you can easily nest them, so I hope we can also have a similar feature in future.

I misunderstood the issue for not reading carefully. So this is about making custom types from exported variables editable in the inspector. I wonder if this is possible with the new inspector. IIRC, the idea was that we could make custom controls for properties.

Can anyone confirm this? cc @reduz

Actually, this could be made to work with categories.

@neikeq so is it already possible? I would love to write some more complex structures and edit them in the editor.

@vnen, as @mysticfall pointed, It is not a static resource, but a living data holder. class Player, Enemy, etc, just containing data. It is important to separate pure data and presentation (Node)

It has been a while since the last comment. Has a final decision been made on it? I'm not asking "when", but rather "if at all" :).
This feature would be extremely useful, especially if applicable to any language.

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

Was this page helpful?
0 / 5 - 0 ratings