Godot Version
v4.3.stable.official [77dcf97d8]
Question
I’m developing an editor plugin that has a 'main screen" and a number of custom control panels and dialogs implemented as scenes. The scene scripts necessarily include the @tool
annotation. A major problem I’ve encountered is the editor scenes rely on initialization that only occurs when the plugin is enabled. If I attempt to edit one of these scenes with the plugin disabled, numerous errors are output to the console window. In a few cases the editor crashes and some of the data files maintained by the plugin are corrupted. This is not a problem if the plugin is enabled while editing the scenes but live editing plugin code while the plugin is enabled can create similar results. The problem comes down to the @tool
scene scripts run when the scenes are opened for editing. That is necessary for custom controls and such to work.
I’ve thought about how to solve the problem. I’ve tried putting checks in the code to detect the difference between the scene being instantiated by the plugin versus the editor but haven’t found a reliable solution.
These are the ideas I’ve considered.
Option 1: Make the @tool
annotation apply to extended scripts. This would allow attaching normal scene scripts (no @tool
) to allow editing the scenes without the nasty side effects. Then the plugin logic can replace the scene’s script with one that extends the non-tool script and includes the tool annotation. For this to work, the @tool
annotation must apply to code contained in the extended script.
Option 2: Provide a way to set a script to ‘tool-mode’ in the plugin code.
Option 3: Provide a way to specify whether the @tool
annotation applies during scene editing.
Are there other options?