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

Fix autoload node cannot be accessed by plugin on start-up #94802

Conversation

Hilderin
Copy link
Contributor

@Hilderin Hilderin commented Jul 26, 2024

I was testing if #92667 fixes the issue #77037. Unfortunately, it does not.

But, I think the issue was caused by that:

  • When the editor is already running, calling add_autoload_singleton creates and adds the autoload into the scene tree directly. So, the get_node("/root/" + AUTOLOAD_NAME) works fine. The autoload is now in the project settings.
  • When the editor is restarted, now that the autoload is in the project settings, the autoload is created before the plugin init but the add_child to the scene is deferred in EditorAutoloadSettings::init_autoloads:
callable_mp((Node *)get_tree()->get_root(), &Node::add_child).call_deferred(info.node, false, Node::INTERNAL_MODE_DISABLED);

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.

@AThousandShips AThousandShips added bug topic:editor cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release topic:plugin labels Jul 26, 2024
@AThousandShips AThousandShips added this to the 4.4 milestone Jul 26, 2024
@apples
Copy link
Contributor

apples commented Aug 11, 2024

Can confirm that this fixes the issue 👍

My test project is quite similar to the MRP.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me if it works.

I checked the blame and this call was added deferred in 2018 by @vnen in 55b4b30, I don't know if you remember why it had to be deferred or if this was done just in case.

@akien-mga akien-mga merged commit 96be44c into godotengine:master Aug 16, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

libklein pushed a commit to libklein/godot that referenced this pull request Aug 16, 2024
…cannot-be-accessed-plugin-start-up

Fix autoload node cannot be accessed by plugin on start-up

NavigationPolygon: Implement get/set_polygon fast paths.

Rebase onto master (4.4).

Fix formating

Prefer set_data when setting polygons and vertices.
@akien-mga
Copy link
Member

Cherry-picked for 4.3.1.

@akien-mga akien-mga removed the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release topic:editor topic:plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autoloaded singleton cannot be accessed at early phase during editor plugin start-up during editor start-up
4 participants