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 errors when re-importing 3D asset files #90531

Conversation

Rindbee
Copy link
Contributor

@Rindbee Rindbee commented Apr 11, 2024

Some 3D asset files (gltf/glb) are treated as scenes and may cause some errors when importing.

Manually updating the cache in advance resulted in some bugs when EditorNode::set_edited_scene() was automatically called for the second update.

When working through different scene tabs, we need to temporarily add the scene root to the SceneTree to ensure that editor_selection->add_node() can work smoothly. This avoids the error message: ERROR: Condition "!p_node->is_inside_tree()" is true.

This also ensures that no other scenes are accidentally added to the SceneTree causing the wrong display. When there is an inherited scene tab open and it is not the current tab, the new root node is accidentally added as a child node of scene_root during replacement.

Instantiate the scene early so caches in SceneState that are cleared due to loading are rebuilt early. This avoids numerous error messages: This operation requires the node cache to have been built.

Supersedes #89428.

Fixes #87451.

Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

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

I'll admit I don't understand this code very well, but currently I get randomly duplicated nodes and this crash constantly and it's driving me nuts.

If this PR has even a remote chance of solving that, I'm in. It can't possibly make things worse than they are now.

@akien-mga akien-mga requested a review from KoBeWi May 7, 2024 09:18
@KoBeWi
Copy link
Member

KoBeWi commented May 7, 2024

The cube is still duplicated 🤔

godot.windows.editor.dev.x86_64_iwSv4PC1m2.mp4

It's gone when you switch scene tab.

@Rindbee Rindbee force-pushed the fix-reload_instances_with_path_in_edited_scenes-in-EditorNode branch 2 times, most recently from bcc99d4 to 6abf458 Compare May 19, 2024 11:55
@Rindbee
Copy link
Contributor Author

Rindbee commented May 19, 2024

Sorry for the late reply.

It reloads scene tabs one by one, so it's better to switch scene tabs first and then process them later.

In addition, it does not seem to save scene modifications when necessary, so re-importing resources may cause the scene to lose unsaved modifications.

@KoBeWi
Copy link
Member

KoBeWi commented May 21, 2024

Something is still wrong:

E90hwCfN2Y.mp4

The level scene gets replaced by test (only visually). It doesn't always happen though. I also had a bug where test.tscn had 2 cubes.

@Rindbee Rindbee force-pushed the fix-reload_instances_with_path_in_edited_scenes-in-EditorNode branch 2 times, most recently from 9566621 to 72b0e83 Compare May 21, 2024 13:49
@Rindbee
Copy link
Contributor Author

Rindbee commented May 21, 2024

Two scenes appear to be open in the 3D screen at the same time. It seems that get_tree()->set_edited_scene_root() is not switched correctly.

@KoBeWi
Copy link
Member

KoBeWi commented May 21, 2024

Now it seems to work correctly, but there is an error spam 🙃

godot.windows.editor.dev.x86_64_9hPF05HkJ5.mp4

Also the current changes make updating scenes after reimport much more expensive. Though maybe it doesn't matter unless someone opens, like, 50 scenes with instances to update.

@Rindbee
Copy link
Contributor Author

Rindbee commented May 22, 2024

Ref<PackedScene> instance_scene_packed_scene = ResourceLoader::load(p_instance_path, "", ResourceFormatLoader::CACHE_MODE_REPLACE, &err);

Reloading a PackedScene clears the cache, which is not rebuilt until instantiate() is called.

int SceneState::find_node_by_path(const NodePath &p_node) const {
ERR_FAIL_COND_V_MSG(node_path_cache.is_empty(), -1, "This operation requires the node cache to have been built.");

@Rindbee Rindbee force-pushed the fix-reload_instances_with_path_in_edited_scenes-in-EditorNode branch 2 times, most recently from 20b2b9d to 9b28fcb Compare May 23, 2024 09:06
@Rindbee
Copy link
Contributor Author

Rindbee commented May 23, 2024

If the scene has unsaved modifications before reimporting, these modifications will not be saved after reimporting, but the unsaved mark (*) will disappear.

Should these modifications be saved before reimporting?

@Rindbee Rindbee force-pushed the fix-reload_instances_with_path_in_edited_scenes-in-EditorNode branch from 9b28fcb to c9f4a92 Compare May 23, 2024 10:48
@Rindbee Rindbee changed the title Fix updating scene root cache twice Fix reload_instances_with_path_in_edited_scenes in EditorNode May 23, 2024
@KoBeWi
Copy link
Member

KoBeWi commented May 23, 2024

IIRC reloading a scene tries to re-apply unsaved changes, so nothing should be lost. Though maybe it's different for regular instances vs imported scenes.

@Rindbee
Copy link
Contributor Author

Rindbee commented May 23, 2024

But it doesn't prompt to save when closing the tab.

Peek.2024-05-23.19-13.mp4

@KoBeWi
Copy link
Member

KoBeWi commented May 23, 2024

That's because the scene does not appear unsaved. It should retain the unsaved status after soft-reload.

@Rindbee Rindbee force-pushed the fix-reload_instances_with_path_in_edited_scenes-in-EditorNode branch from c9f4a92 to dfe3468 Compare May 23, 2024 14:01
@KoBeWi
Copy link
Member

KoBeWi commented May 29, 2024

Needs rebase due to conflicts >_>

Some 3D asset files are treated as scenes and may cause some errors when
importing.

When working through different scene tabs, we need to temporarily add
the scene root to the SceneTree to ensure that `editor_selection->add_node()`
can work smoothly. This avoids the error message: `ERROR: Condition
"!p_node->is_inside_tree()" is true.`

This also ensures that no other scenes are accidentally added to the
SceneTree causing the wrong display. When there is an inherited scene
tab open and it is not the current tab, the new root node is accidentally
added as a child node of `scene_root` during replacement.

Instantiate the scene early so caches in SceneState that are cleared
due to loading are rebuilt early. This avoids numerous error messages:
`This operation requires the node cache to have been built.`
@Rindbee Rindbee force-pushed the fix-reload_instances_with_path_in_edited_scenes-in-EditorNode branch from dfe3468 to 9fe902b Compare May 30, 2024 00:20
@Rindbee Rindbee changed the title Fix reload_instances_with_path_in_edited_scenes in EditorNode Fix errors when re-importing 3D asset files May 30, 2024
@Rindbee
Copy link
Contributor Author

Rindbee commented May 30, 2024

The conflict has been resolved.

The latest commit in master no longer restores the property changes caused by the import, which should refresh the 3D Screen to show the latest changes, but it seems that only the inherited scene will be refreshed, not other scenes. It needs to be reloaded to refresh.

@akien-mga akien-mga merged commit d9609ff into godotengine:master May 30, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@Rindbee Rindbee deleted the fix-reload_instances_with_path_in_edited_scenes-in-EditorNode branch May 30, 2024 22:11
@Bonkahe
Copy link

Bonkahe commented Jun 1, 2024

I apologize for adding a comment here, not sure if I should have just posted it in the issue (bit new to issues and all of this honestly), but here goes.
I believe this commit is causing an issue, I posted an issue here: #92623

While this appears to be an intended result, this is more or less destroying my functionality, or I suppose to some degree a lot of tool functionality that depends on enter_tree, in my case rebuilding my terrain every time I reimport any resource, this includes the resources that are part of the terrain being generated, resulting in an endless loop.

I believe the implementation of this commit should be re-reviewed, as this method of fixing the errors when re-importing assets has some pretty impactful downsides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants