0 votes

So I've gone through this doc article on how to create a basic editor plugin using GDScript and have made a few simple plugins. I've also developed a custom module in C++. What I was wondering is whether it's possible to write another editor plugin but using C++ instead without modifying the Godot's source.

It seems like I've already figured out how to write an editor plugin by looking how other built-in plugins are implemented as in here.

In editor_node.cpp I discovered that plugins are registered during initialization of EditorNode, for instance:

add_editor_plugin(memnew(VisualShaderEditorPlugin(this)));

So it appears to me that I could use EditorNode singleton and add my plugin like this within a module:

EditorNode *en = EditorNode::get_singleton()
en->add_editor_plugin(memnew(AnlNoiseEditorPlugin(en))

The problem is that I don't know when and where to do this. I've tried doing so in register_types:

void register_my_module_types() {

    ClassDB::register_class<MyModule>();

    EditorNode *en = EditorNode::get_singleton();
    en->add_editor_plugin(memnew(MyModuleEditorPlugin(en)));
}

And en is NULL here because it seems like EditorNode is not even initialized yet, so I wonder what to do now.

in Engine by (1,378 points)
edited by

1 Answer

0 votes

The solution is fairly straightforward, I just had to use EditorPlugins to add a plugin:

void register_my_module_types() {

    ClassDB::register_class<MyModule>();

#ifdef TOOLS_ENABLED
    EditorPlugins::add_by_type<MyModuleEditorPlugin>();
#endif
}
by (1,378 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 Frequently asked questions and 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 [email protected] with your username.