Skip to content

Conversation

@xuhuisheng
Copy link
Contributor

@xuhuisheng xuhuisheng commented Sep 29, 2025

There are so many problems when invoking Clear Inheritance

  • After confirm 'Clear Inheritance? (No Undo)', the scene didn't do save really.
  • There is no unsaved (*) mark on the title of editor.
  • The children node of scene root cannot be renamed.
  • The signal in the right side NodeDock is readonly.

There latest comment gives me a clue, that we can save scene and reload scene directly, then all of these issues resolved.


Edit:

Follows KobeWi suggestion, don't save and reload scene, but update node in memory and mark unsaved.

@xuhuisheng xuhuisheng requested a review from a team as a code owner September 29, 2025 07:03
@xuhuisheng xuhuisheng force-pushed the dev/clear_inheritance branch from bde25d0 to 319b306 Compare September 29, 2025 07:05
@xuhuisheng xuhuisheng changed the title Fix Clear Inheritance error Fix Clear Inheritance issues Sep 29, 2025
@AThousandShips AThousandShips added this to the 4.6 milestone Sep 29, 2025
@xuhuisheng xuhuisheng force-pushed the dev/clear_inheritance branch from 319b306 to 8470819 Compare September 29, 2025 08:54
@KoBeWi
Copy link
Member

KoBeWi commented Oct 14, 2025

Is it possible to achieve the same without saving and reloading scene? If the scene is not saved, you can "undo" the change by reloading the scene, which is useful option.

You can clear scene's undo history and it will mark the scene as unsaved with no way of undo. Not sure about other problems, but it should be possible to fix them too.

@xuhuisheng
Copy link
Contributor Author

Is it possible to achieve the same without saving and reloading scene? If the scene is not saved, you can "undo" the change by reloading the scene, which is useful option.

I can give it a try, but recreating the entire hierarchy, as reloading it from a file, would need lots of works.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 14, 2025

I think the problem is that update_tree() does not take effect for some reason (or it's updated wrong). The fix might be simply forcing a refresh. It should be possible without reload, and without lots of changes.

For a hacky solution, calling scene_tree->set_valid_types({}) will force full tree update, but I think a dedicated method would be better.

@xuhuisheng
Copy link
Contributor Author

xuhuisheng commented Oct 14, 2025

I think the problem is that update_tree() does not take effect for some reason (or it's updated wrong). The fix might be simply forcing a refresh. It should be possible without reload, and without lots of changes.

In my investigation, the "Clear Inheritance" operation is not complete. It only clean inheritated_state and emit an event, without clear all of it's children state. So after update_tree, we still get the old children's state.

godot/scene/main/node.cpp

Lines 2809 to 2813 in e825169

void Node::set_scene_inherited_state(const Ref<SceneState> &p_state) {
ERR_THREAD_GUARD
data.inherited_state = p_state;
_emit_editor_state_changed();
}

And before "Clear Inheritance", there is only one node with a reference for an "ext_resource".

[ext_resource type="PackedScene" uid="uid://bowuloxmdkrly" path="res://prefab.tscn" id="1_by10c"]
[node name="PrefabChildToTest" instance=ExtResource("1_by10c")]

After "Clear Inheritance", we need create the real tree structure for the new scene.

[ext_resource type="Script" uid="uid://cdao4baykx3v" path="res://prefab.gd" id="1_3o2mv"]
[node name="PrefabChildToTest" type="Node2D"]
script = ExtResource("1_3o2mv")
[node name="Node2D" type="Node2D" parent="."]
[connection signal="draw" from="Node2D" to="." method="_on_node_2d_draw"]

I agree the current PR is not so good. I can do more digging to find a better solution.


Edit:

scene_tree->set_valid_types({}) can resolve the left menu tree warning, but signal warning on Inspector is still.
I will keep digging.

@xuhuisheng xuhuisheng force-pushed the dev/clear_inheritance branch 6 times, most recently from be8b9c7 to 8591ece Compare October 18, 2025 04:26
@xuhuisheng
Copy link
Contributor Author

xuhuisheng commented Oct 18, 2025

@KoBeWi

I found check_and_update_scene() supports reload scene from memory. Please take a look when you have time.

BTW: There is a compilation error on windows platform. Looks like ret_nodes maybe unintiliazed on some situations. I don't know how to fix it, yet.

scene\resources\packed_scene.cpp:702:27: error: '*ret_nodes' may be used uninitialized [-Werror=maybe-uninitialized]
  702 |         return ret_nodes[0];

Maybe related this: #111771

@xuhuisheng xuhuisheng force-pushed the dev/clear_inheritance branch 2 times, most recently from 4480a27 to 9ab4be7 Compare October 18, 2025 07:32
@xuhuisheng xuhuisheng force-pushed the dev/clear_inheritance branch from 9ab4be7 to 91f257d Compare October 29, 2025 13:08
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

Some minor details left, but the implementation looks ok now.

@xuhuisheng xuhuisheng force-pushed the dev/clear_inheritance branch from 91f257d to 766b45b Compare October 29, 2025 13:27
@Repiteo Repiteo merged commit 0994b19 into godotengine:master Oct 29, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 29, 2025

Thanks!

@xuhuisheng xuhuisheng deleted the dev/clear_inheritance branch October 30, 2025 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clear Inheritance on Inherited Scene from base Scene with children with signals does not unlock signals until editor restart

4 participants