Wednesday, April 30, 2025
spot_img

c++ – Tips on how to make a GDExtension customized node draw within the Godot 4.3 editor?


I am working with Godot 4.3 utilizing GDExtension and C++. I created a customized class known as Participant that inherits from Management. Within the _draw() methodology, I am attempting to attract a easy crimson rectangle. It really works once I run the scene, however once I add the Participant node to the scene within the editor, nothing exhibits up — the rectangle does not render within the editor.

This is the related code:

// participant.h
#ifndef __BYTENOL_CHESS_PLAYER_H__
#outline __BYTENOL_CHESS_PLAYER_H__

#embody 

#embody "piece.h"
#embody "ChessGrid.h"


namespace godot
{

    class Participant: public Management
    {
        GDCLASS(Participant, Management)

        personal:
            bool isWhite{ };

        protected:
            static void _bind_methods();

        public:
            Participant();
            ~Participant();
            void _ready() override;
            void _draw() override;


            inline void set_isWhite(bool b);
            inline bool get_isWhite() const;
    };


    inline void Participant::set_isWhite(bool b)
    {
        isWhite = b;
        queue_redraw();
    };

    inline bool Participant::get_isWhite() const
    {
        return isWhite;
    }

}


#endif
// participant.cpp
#embody "participant.h"

void godot::Participant::_bind_methods()
{
    ClassDB::bind_method(D_METHOD("set_isWhite"), &Participant::set_isWhite);
    ClassDB::bind_method(D_METHOD("get_isWhite"), &Participant::get_isWhite);
    ADD_PROPERTY(PropertyInfo(Variant::BOOL, "isWhite"), "set_isWhite", "get_isWhite");
}

godot::Participant::Participant()
{
    queue_redraw();
}

godot::Participant::~Participant()
{
}

void godot::Participant::_ready()
{
    queue_redraw();
}

void godot::Participant::_draw()
{
    Rect2i rect{ 0, 0, 100, 100 };
    Colour shade{ 255, 0, 0, 255 };
    draw_rect(rect, shade);
}

I’ve made certain the .gdextension file consists of software = true:

[configuration]
entry_symbol = "lib_chess_init"
compatibility_minimum = "4.3"
software = true

However the rectangle nonetheless does not render contained in the editor viewport.

After I add the Participant node to the scene within the editor, I would like the crimson rectangle to look instantly, identical to it does at runtime. How do I obtain this. I’ve spent greater than 10 hours looking for an answer.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles