Skip to content

Commit 06d9bcd

Browse files
Document sub plugins
1 parent 87812dc commit 06d9bcd

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed
14.9 KB
Loading
14.9 KB
Loading

tutorials/plugins/editor/making_plugins.rst

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ click the button, you can see some text in the console:
282282
.. image:: img/making_plugins-custom_node_console.webp
283283

284284
A custom dock
285-
^^^^^^^^^^^^^
285+
~~~~~~~~~~~~~
286286

287287
Sometimes, you need to extend the editor and add tools that are always available.
288288
An easy way to do it is to add a new dock with a plugin. Docks are just scenes
@@ -413,18 +413,6 @@ the settings window. You should now have a custom dock:
413413

414414
.. image:: img/making_plugins-custom_dock.webp
415415

416-
Going beyond
417-
~~~~~~~~~~~~
418-
419-
Now that you've learned how to make basic plugins, you can extend the editor in
420-
several ways. Lots of functionality can be added to the editor with GDScript;
421-
it is a powerful way to create specialized editors without having to delve into
422-
C++ modules.
423-
424-
You can make your own plugins to help yourself and share them in the
425-
`Asset Library <https://godotengine.org/asset-library/>`_ so that people
426-
can benefit from your work.
427-
428416
.. _doc_making_plugins_autoload:
429417

430418
Registering autoloads/singletons in plugins
@@ -450,12 +438,12 @@ Use the following code to register a singleton from an editor plugin:
450438
const AUTOLOAD_NAME = "SomeAutoload"
451439

452440

453-
func _enter_tree():
441+
func _enable_plugin():
454442
# The autoload can be a scene or script file.
455443
add_autoload_singleton(AUTOLOAD_NAME, "res://addons/my_addon/some_autoload.tscn")
456444

457445

458-
func _exit_tree():
446+
func _disable_plugin():
459447
remove_autoload_singleton(AUTOLOAD_NAME)
460448

461449
.. code-tab:: csharp
@@ -469,15 +457,62 @@ Use the following code to register a singleton from an editor plugin:
469457
// Replace this value with a PascalCase autoload name.
470458
private const string AutoloadName = "SomeAutoload";
471459

472-
public override void _EnterTree()
460+
public override void _EnablePlugin()
473461
{
474462
// The autoload can be a scene or script file.
475463
AddAutoloadSingleton(AutoloadName, "res://addons/MyAddon/SomeAutoload.tscn");
476464
}
477465

478-
public override void _ExitTree()
466+
public override void _DisablePlugin()
479467
{
480468
RemoveAutoloadSingleton(AutoloadName);
481469
}
482470
}
483471
#endif
472+
473+
Using sub-plugins
474+
~~~~~~~~~~~~~~~~~
475+
476+
Often a plugin adds multiple things, for example a custom node and a panel.
477+
In those cases it might be easier to have a separate plugin script for each of those features.
478+
Sub-plugins can be used for this.
479+
480+
First create all plugins and sub plugins as normal plugins:
481+
482+
.. image:: img/sub_plugin_creation.webp
483+
484+
Then move the sub plugins into the main plugin folder:
485+
486+
.. image:: img/sub_plugin_moved.webp
487+
488+
Godot will hide sub-plugins from the plugin list, so that a user can't enable or disable them.
489+
Instead the main plugin script should enable and disable sub-plugins like this:
490+
491+
.. tabs::
492+
.. code-tab:: gdscript GDScript
493+
494+
@tool
495+
extends EditorPlugin
496+
497+
# The main plugin is located at res://addons/my_plugin/
498+
const PLUGIN_NAME = "my_plugin"
499+
500+
func _enable_plugin():
501+
EditorInterface.set_plugin_enabled(PLUGIN_NAME + "/node", true)
502+
EditorInterface.set_plugin_enabled(PLUGIN_NAME + "/panel", true)
503+
504+
func _disable_plugin():
505+
EditorInterface.set_plugin_enabled(PLUGIN_NAME + "/node", false)
506+
EditorInterface.set_plugin_enabled(PLUGIN_NAME + "/panel", false)
507+
508+
Going beyond
509+
~~~~~~~~~~~~
510+
511+
Now that you've learned how to make basic plugins, you can extend the editor in
512+
several ways. Lots of functionality can be added to the editor with GDScript;
513+
it is a powerful way to create specialized editors without having to delve into
514+
C++ modules.
515+
516+
You can make your own plugins to help yourself and share them in the
517+
`Asset Library <https://godotengine.org/asset-library/>`_ so that people
518+
can benefit from your work.

0 commit comments

Comments
 (0)