|
@@ -399,3 +399,35 @@ C++ modules.
|
|
|
You can make your own plugins to help yourself and share them in the
|
|
|
`Asset Library <https://godotengine.org/asset-library/>`_ so that people
|
|
|
can benefit from your work.
|
|
|
+
|
|
|
+.. _doc_making_plugins_autoload:
|
|
|
+
|
|
|
+Registering autoloads/singletons in plugins
|
|
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
+
|
|
|
+It is possible for editor plugins to automatically register
|
|
|
+:ref:`autoloads <doc_singletons_autoload>` when the plugin is enabled.
|
|
|
+This also includes unregistering the autoload when the plugin is disabled.
|
|
|
+
|
|
|
+This makes setting up plugins faster for users, as they no longer have to manually
|
|
|
+add autoloads to their project settings if your editor plugin requires the use of
|
|
|
+an autoload.
|
|
|
+
|
|
|
+Use the following code to register a singleton from an editor plugin:
|
|
|
+
|
|
|
+::
|
|
|
+
|
|
|
+ tool
|
|
|
+ extends EditorPlugin
|
|
|
+
|
|
|
+ # Replace this value with a PascalCase autoload name, as per the GDScript style guide.
|
|
|
+ const AUTOLOAD_NAME = "SomeAutoload"
|
|
|
+
|
|
|
+
|
|
|
+ func _enter_tree():
|
|
|
+ # The autoload can be a scene or script file.
|
|
|
+ add_autoload_singleton(AUTOLOAD_NAME, "res://addons/my_addon/some_autoload.tscn")
|
|
|
+
|
|
|
+
|
|
|
+ func _exit_tree():
|
|
|
+ remove_autoload_singleton(AUTOLOAD_NAME)
|