C# Export in Control.tscn is not work

Godot Version

v4.2.2.stable.mono.official [15073afe3]

Question

I made this cord.

using Godot;
using System;

public partial class DebugLabel : Control
{
    [Export]
    public ColorRect m_Rect { get; set; }
    [Export]
    public Label m_Label { get; set; }


    [Export]
    public String LabelString
    {
        get { return m_Label.ToString(); }
        set
        {
            GD.Print("LabelString");
            m_Label.Text = value;
        }
    }

    [Export]
    public Color Color
    {
        get { return m_Rect.Color; }
        set
        {
            m_Rect.Color = value;
        }
    }
}

I set those.

And I put this on other scene, but m_Label and m_Rect are always null.

I’m hoping that when the Inspector’s LabelString is changed, the Label in Control will also change, but it’s not working.

Please help me!

I believe you need the [Tool] keyword at the top of your class to make sure the code can run inside the editor / inspector, otherwise this code will only run while the game itself is running.

1 Like

This solved it! Thank you!

If you don’t mind, I’d like to know how you found out about it so I can use it as a reference when researching Godot.

1 Like

Thank you again!

It’s pretty immature to miss that’s written in the official document, so I’ll study hard.

1 Like