<!--210527,210402-->
<h1>how to make a plugin for godot engine </h1>
april 15, 2021<br>
#godotengine <br>
<br>
If Godot Engine doesn't have the functionality you need, you can extend it with your own plugins. You can also use it to make specialized nodes to suit your project. <br>
<br>
<h2>how to make a plugin </h2><br>
<br>
Navigate to your project folder. Within it, make a folder called <b>addons</b>. Within the addons folder, make a folder and name it after your plugin. Within the plugin folder, you will need a few files: plugin.cfg, custom_node.gd, a .gd file for each custom node your plugin will add, and a .png icon for your custom nodes. <br>
<br>
<h3>plugin.cfg </h3><br>
Within the plugin file, make a file called <b>plugin.cfg</b>. Open it in a simple text editor like Notepad and use this template to make your config: <br>
<br>
[plugin]<br>
name="World"<br>
description="A world system."<br>
author="chimchooree"<br>
version="0.4"<br>
script="custom_node.gd"<br>
<br>
Obviously, fill the space within the quotation marks with your own information. The script's value should be kept the same, though. Once you have these six lines in your file, save and close. Avoid writing these files in a full word processor like Microsoft Word because they tend to fill your documents with extra characters. Even if they aren't displayed in the word processor, they will make your file unreadable to Godot.  <br>
<br>
<br>
<h3>custom_node.gd </h3><br>
Within the plugin file, make another file called <b>custom_node.gd</b>. The contents of this node should look like this: <br>
<br>
tool <br>
extends EditorPlugin<br>
<br>
func _enter_tree():<br>
&nbsp;&nbsp;&nbsp;&nbsp;add_custom_type("Room", "Node2D", preload("room.gd"), preload("World.png"))<br>
<br>
func _exit_tree():<br>
&nbsp;&nbsp;&nbsp;&nbsp;remove_custom_type("Room")<br>
<br>
To add a type, supply the <b>add_custom_type</b> method with 4 parameters: the name of your custom node, the node type (Node2D, AnimatedSprite, etc), your custom node's preloaded script, and a preloaded icon. Every type you add must also be removed. Use this process to add as many custom nodes as you need. <br>
<br>
<br>
<h3>.gd files </h3><br>
For each custom node you declare in the custom_node.gd file, you'll need to supply a .gd script. These are going to look just like your other scripts in the editor. You can write them in full now or leave them relatively blank, but at least declare the type at the top. <br>
<br>
Since my example calls for a Node2D with a "room.gd", I can make a file within the plugins folder called <b>room.gd</b>. I'll keep the contents extremely simple for now: <br>
<br>
extends Node2D <br>
<br>
<br>
<h3>icon </h3><br>
Icon must be .png files with the dimensions of 16x16 pixels. They are just for you to see within the editor's node tree, so you can draw something fancy or just squish down the same Godot head everyone uses. You can also make a unique icon for each node or just use the same one across all nodes. Just make sure the file name matches what's used in custom_node.gd. <br>
<br>
If you want to use my squished icon, that's 100% fine with me. If you need to check the license for the original Godot head, though, it's on their <a href="https://github.com/godotengine/godot/blob/master/LOGO_LICENSE.md">git repo</a>. <img src="/static/img/ent/plugin_icon.png" alt="(image: Squished Godot head)"> <br>
<br>
When choosing whether to make something beautiful or lazy, let Colossians 3:23 echo in your head: "And whatever you do, do it heartily, as to the Lord and not to men." <br>
<br>
<br>
<h2>how to add a plugin </h2><br>
Now, inside Godot Engine's editor, go to the top-left menu and select Project>Project Settings and go to the Plugins tab. If your files came out okay, your new plugin should appear in the listing with all the data from your plugin.cfg file. Under the Status heading, make sure the plugin is set to "Enable" or "Active". To check whether your plugin's working, try to add a new node to a scene and search for your custom type. It should pop up with your custom icon in the search. If you add it, it will already have its custom script attached and ready to go. <br>
<br>
Happy coding! <br>
<br>
<br>
Last updated April 30, 2021 <br>
<br>
