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.

asked Oct 1, 2018 in Engine by Xrayez (1,161 points)
edited Oct 1, 2018 by Xrayez

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
}
answered Oct 29, 2018 by Xrayez (1,161 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.