How can I convert a module native to Godot Engine into a plugin? (specifically the gridmap module in this case)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KnightNine

I want to edit how GridMap nodes work and create my own custom version of that node that uses hexagonal prisms instead of a straight cube grid for positioning. I got the source-code for the GridMap module from github but the code is in C++, Python, and XML. Can i get this to run as an in-engine plugin or should I just start from scratch?

If this is feasible to do, my questions would be:

  • How can i get the files in these other coding languages to function in the editor?
  • What files from the Gridmap folder are actually relevant for this module to function as a plugin?
  • Are there any tutorials relevant to this?

Thank you

:bust_in_silhouette: Reply From: KnightNine

Modules have access to more control over Godot than plugins do, so I don’t think it’s possible.
It’s also just more efficient to rotate the grid 45 degrees and place hexes like that but i haven’t tested it yet.

:bust_in_silhouette: Reply From: Xrayez

I’m not sure if there’s anything module-related which would make it impossible to port this to a GDScript plugin. The C++ editor plugin initialization works similarly to GDScript.

class GridMapEditorPlugin : public EditorPlugin
...
public:
    GridMapEditorPlugin(EditorNode *p_node);

is quite similar to:

tool
class_name GridMapEditorPlugin
extends EditorPlugin

(you can even write this as a one-liner):

class_name GridMapEditorPlugin tool extends EditorPlugin

All other plugin-related methods reflect the current EditorPlugin documentation.

If there are some Controls which are not exposed to the editor via script, these need to be re-implemented unfortunately.

One of the things which is lacking is the support for documentation the way it’s done via modules, but this isn’t a priority anyway.

I haven’t done any existing module ports to GDScript yet, but you can take a look at this repository as a proof that there are certainly some classes which can be ported from C++ back to GDScript. If you do manage to port GridMap to GDScript, feel free to contribute before doing your custom modifications to it. :slight_smile:

If you talk about GDNative plugins specifically, I think that’s also doable.

Checkout editor plugins documentation too. I haven’t seen C++ specific documentation for this.