+1 vote

Hi,
I would like to export a custom type variable on the inspector when i try to i get the error :
modules/mono/csharpscript.cpp:2219 - Unknown type of exported member: MyNode.m
modules/mono/csharp
script.cpp:2219 - Unknown type of exported member: MyNode.ms

MyCode :
public class MyType
{
public string name;
public int i;
}

public class MyNode : Node2D
{
    [Export]
    MyType[] ms;
    [Export]
    MyType m;
}

    public class MyType
{
    public string name;
    public int i;
}

public class MyNode : Node2D
{
    [Export]
    MyType[] ms;
    [Export]
    MyType m;
}

Is there a way to display custom types in Godot Inspector using C#?

asked Sep 6, 2019 in Engine by lazlo (22 points)

1 Answer

0 votes

Godot doesn't support exporting arbitrary types, it has to be a primitive type or a Resource (which can be a custom one).

I haven't done that often and I don't use C# in Godot, but here are some suggestions:
If you want to export your custom type you could make it inherit Resource and export it as Resource.
Then in the inspector, under the property, create a new Resource, and add your custom resource script on it. At least, that's how it can work in GDScript.
If that doesn't work, try to make your field a Resource instead of MyClass, then cast it to obtain your derived type.

You could bypass the extra step of adding resource + adding script by registering your class with a global class name so it will appear in the New Resource dialog (a Godot feature, not related to C#) but I haven't tried with C#.

answered Sep 6, 2019 by Zylann (26,784 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.