godot-proposals
godot-proposals copied to clipboard
Add an EditorPlugin signal for a requested scene change
Describe the project you are working on
I am making a plugin that lets multiple people collaborate on a project in real time.
Describe the problem or limitation you are having in your project
I couldn't find an intuitive way of detecting whether the SceneTree's node_added/node_removed signals are caused by the user adding/removing a Node, or because of a scene switch. This is necessary to know in order to properly sync Node creations and deletions to the other connected peers.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
By adding a signal that emits right before a SceneTree gets modified in any way, I can know which edits are made by the user and which are purely because of the switch to another scene. By using the already existing scene_changed signal, I know when to start syncing changes again, the only missing piece is a signal that emits right before a scene change happens (such as "scene_change_requested").
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
When the user switches to a different scene, Godot will call the scene_change_requested signal before any changes to the SceneTree are done.
If this enhancement will not be used often, can it be worked around with a few lines of script?
This is very difficult and involves accessing Godot's internal UI, which is not very addon-friendly. It will also break when addons such as script-tabs are used, as they modify the relevant internal UI by quite a bit.
Is there a reason why this should be core and not an add-on in the asset library?
Same as the above reason, and a signal has to be added in core.
A possible workaround I found that could be used for this depends on EditorPlugin: expose class for SceneDock https://github.com/godotengine/godot-proposals/issues/9798.
(this is a workaround, having a dedicated signal would still be much preferred.)
If I got this right here's the source for removing old / adding new edited scene (for reference): https://github.com/godotengine/godot/blob/b377562b52fa8a68a99d5e818d8e08ac8d3fd7da/editor/editor_node.cpp#L3941-L3966