In this series I want to share a few things that I love about the Godot Game Engine. Today's post is about extending the editor itself.
When using open source software I sometimes hear the statement "You can do anything and adjust it to your needs since it is open source". While this may be true, it can be very hard to actually adjust things to fit your needs. However it can also be very easy! Godot is great to extend. You have multiple methods available to adjust it to your needs. It feels like the engine was made with extendability in mind.
The Godot Editor is basically a game running in the Godot Engine. When you are already familiar with Godot then it is really easy to get started with extending the editor itself.
There are multiple methods to extend the editor. They range from easy to very complex (but powerful).
This method is one of the easiest methods to extend the editor. You can add the
tool keyword to the top of any script. Every script with this keyword will not only run in the game but also inside the editor (when a node with that script is in the scene). What you can do with this is a bit limited as the script must be attached to a node in a scene. This method is really useful to create helpers for yourself.
I use this method quite often to quickly add a preview that updates itself based on some values. Here is a small example from one of my games:
tool extends BaseEnemy export(ENEMY_COLOR) var color := ENEMY_COLOR.RED setget set_color func set_color(new_value: int): color = new_value set_enemy_sprite(SPRITES[color])
Here is what the code does: Whenever the enemies
color property is changed the sprite is updated to match the new color. This allows to immediately see the changes you make inside the editor.
Plugins are much more powerful than the toolmode. In contrast to tool scripts they are executed when the editor starts and the plugin is enabled. They are not part of your scenes, instead they run independently inside the editor. Here are a few things you can do with plugins:
- Add custom node types
- Add docks and menu items to display custom UI Elements in the editor
- Make a custom importer/exporter for your own format
- Manipulate nodes in the currently edited scene
I used plugins to create a custom map editor for a game.
This is the most powerful method I have used so far. You can create your own engine modules in C++. Godot uses scons for building. Godots build system and structure makes it relatively easy to add your own modules.
You can basically access everything with C++. Additionally C++ does run faster than GDScript. In most cases this is not really important. However I ran into two cases where I needed to use C++:
- Extending a physics body. GDScript simply wasn't fast enough for my usecase.
- Using thirdparty C++ libraries. I needed methods to operate on graphs (like shortest path, checking if graph is directed, checking if it is acyclic and so on). I didn't want to built this all by myself, so I added a thridparty C++ library as a module.
It is nice to have this possibility. However for most things GDScript is sufficient.
This is the third post in my series "Things I love about Godot". I already have some ideas for the following posts. If you have any questions or suggestions please let me know! If you would like more details or a tutorial regarding a specific aspect feel free to ask.