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

Wasteful idiom in the Godot Editor: monitoring every node removed across various plugins. #102207

Open
migueldeicaza opened this issue Jan 30, 2025 · 2 comments

Comments

@migueldeicaza
Copy link
Contributor

Tested versions

Godot 4.3, Godot/master

System information

MacOS

Issue description

There is an idiom in the Editor where plugins connect to the SceneTree "node_removed" signal. They do this to determine when a node has been removed from the scene, and their editing capabilities are no longer needed. For example, the AnimationTrackEditor registers this handler to keep the content "sticky" at the bottom of the screen, regardless of which object is being edited.

The problem with this idiom is that it gets notified of every node removed from the scene. For example, I clicked on a simple dialog to create a node, and this triggered 600 invocations to the AnomationPlayerEditor::_node_removed, this was a dialog that was not related to animations at all, but this callback is invoked for everything.

To make things a little worse, this idiom is not limited to the AnimationEditor, there are 26 instances of this idiom (judging from a quick grep) in the editor.

I believe that we can achieve the same by monitoring tree_exiting signal on the node we want to monitor, as it seems to be called in the same condition.

@KoBeWi suggested on the chat room that there is a system in Godot to handle this scenario, but I am not familiar with that system.

Steps to reproduce

Set a breakpoint in AnimationPlayerEditor::_node_removed, then select an animation in Godot.

Then add an item to the canvas, like "Node2D", tap create, and watch how it takes 600 hits to the callback.

Minimal reproduction project (MRP)

No minimal project is needed, any project will do.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 30, 2025

Ever since #71770, deleting a node will automatically notify all editors to stop editing it, so some (if not all) of the monitoring checks are redundant.

@migueldeicaza
Copy link
Contributor Author

The adding using this idiom do not rely on the edit(nullptr) pattern to determine whether to stop previewing their resource, and I am not sure they have a system to do this.

The scenario where I discovered this was editing an AnimationPlayer, it keeps track of this node and will ignore requests to edit nullptr as "none of my business", instead it waits for the node that it is tracking to be removed from the scene to give up the editing of that object

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

No branches or pull requests

2 participants