Fix autoload node cannot be accessed by plugin on start-up #94802
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was testing if #92667 fixes the issue #77037. Unfortunately, it does not.
But, I think the issue was caused by that:
add_autoload_singleton
creates and adds the autoload into the scene tree directly. So, theget_node("/root/" + AUTOLOAD_NAME)
works fine. The autoload is now in the project settings.add_child
to the scene is deferred inEditorAutoloadSettings::init_autoloads
:Then, the plugin is initialized and added to the scene and oups, we are in a situation where the plugin
_entre_tree
is executed before the autoload is added the the scene.So, the solution was to call add_child directly, no deferred in
EditorAutoloadSettings::init_autoloads
. I think that was not possible before #92303 because the autoloads were created way earlier.This is a simple MRP to reproduce the problem:
test-godot-plugin-autoload-with-resource.zip
Note: This is an alternative solution to #86453 that fixes the problem without changing any loading order.