How can I make [Export] keyword work in my own class

Natt007Natt007 Posts: 5Member
edited June 25 in Programming

The last thing I tried is to use a nested class to make it work but it really doesn't
Previously it was outside this class.
I would be grateful if you could show me how to do it.

using Godot;
using System;

public class Enemy : KinematicBody2D
{
    // Declare member variables here. Examples:
    // private int a = 2;
    // private string b = "text";

    // Called when the node enters the scene tree for the first time.

[Export]
public int SPEED = 30;


public class EnemySettings
{
    //This doesn't show in GoDot
 [Export]
    public int GRAVITY =10;

    public Vector2 FLOOR { get; } = new Vector2(0,-1);
}

Tags :

Comments

  • MegalomaniakMegalomaniak Posts: 2,625Admin

    Looks like you might have a syntax issue there. A curly bracket is missing. Or are you just copying a part of the script here?

  • Natt007Natt007 Posts: 5Member

    No syntax error. I didn't copy the whole code. It should easily be reproducible if you use nested classes and try to use [Export] in the nexted class.
    If you want however I can send you the whole file.

  • TwistedTwiglegTwistedTwigleg Posts: 2,641Admin

    Are the two classes in the same file, or two different files? If they are in the same file, that could be causing the issue. In GDScript, Godot treats each file as a single class, with classes defined in that class as a sub-class, and I think sub-classes exports do not work in GDScript. This may also be the case with C#, where Godot thinks it is a subclass and therefore doesn't show the exported property.

  • Natt007Natt007 Posts: 5Member

    @TwistedTwigleg said:
    Are the two classes in the same file or two different files? If they are in the same file, that could be causing the issue. In GDScript, Godot treats each file as a single class, with classes defined in that class as a sub-class, and I think sub-classes exports do not work in GDScript. This may also be the case with C#, where Godot thinks it is a subclass and therefore doesn't show the exported property.

    That could be the case. I don't get any compilation error so it is simply because GoDot doesn't support it.
    Thanks TT :)

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file