Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding autoloads from custom plugin: example in the doc is bad practice #9571

Closed
smedelyan opened this issue Jul 2, 2024 · 1 comment · Fixed by #9873 or #9979
Closed

Adding autoloads from custom plugin: example in the doc is bad practice #9571

smedelyan opened this issue Jul 2, 2024 · 1 comment · Fixed by #9873 or #9979
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation discussion enhancement

Comments

@smedelyan
Copy link

Your Godot version: 4.2.2 and 4.3.beta-2

Issue description: see the doc at link below. It shows an example of adding and removing autoloads in _enter_tree(), _exit_tree(). I think this is not correct way to to do this because:

  • This messes up the order of autoloads that the user may have defined
  • This does not preserve the order of autoloads, if the user reordered them
  • This sometimes causes problems, e.g. an autoload is added by such plugin much later than compiler checks for the presence of this autoload when it is already referenced from other code / autoloads
  • This is just ineffective. No need to add & remove autoload each time the editor starts up and shuts down

The problem is much worse than it may look at the first glance, because some plugins out there already follow this bad practice.

Correct me if I'm wrong, but the proper way to add autoloads from a plugin is:

@tool
extends EditorPlugin

func _enable_plugin() -> void:
	add_autoload_singleton("MyAutoload", "res://my_autoload.gd")

func _disable_plugin() -> void:
	remove_autoload_singleton("MyAutoload")

URL to the documentation page (if already existing): https://docs.godotengine.org/en/stable/tutorials/plugins/editor/making_plugins.html#registering-autoloads-singletons-in-plugins

@skyace65 skyace65 added the area:manual Issues and PRs related to the Manual/Tutorials section of the documentation label Jul 8, 2024
@HolonProduction
Copy link
Member

I'd also say that is not the best way to do it. See also godotengine/godot#94249 for another reason why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation discussion enhancement
Projects
None yet
4 participants