+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#?

in Engine by (26 points)

2 Answers

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#.

by (27,897 points)
0 votes
by (14 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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.