Godot Plugin Tool Script Type Detection

When you have a tool script attached to a node in Godot’s editor, it will run both while you are editing the scene, and when it is attached to the editor itself. You can differentiate between which ‘kind’ is runnig by checking the viewport:

if (GetViewport()?.Name != "root") {
    return;
}

The edited scene will not have the root viewport as its nearest viewport.