Quick answer: Guard with ResourceLoader.Exists(path). Defer first load to _Ready if needed.
[Tool] script in editor uses GD.Load to fetch a default. Returns null. Resource not yet imported into the database when tool runs.
The Fix
[Tool]
public partial class EditorWidget : Node {
PackedScene _defaultScene;
public override void _Ready() {
if (ResourceLoader.Exists("res://defaults/widget.tscn")) {
_defaultScene = ResourceLoader.Load<PackedScene>(
"res://defaults/widget.tscn");
}
}
}
Exists check avoids the null. ResourceLoader.Load with type parameter gives type-safe result.
Verifying
Tool script in editor: scene loads when path exists. After Reimport: load succeeds. Without guard: NullReferenceException at first edit.
“Exists check. Then load. Tool stays alive.”
Related Issues
For C# async deadlock, see async deadlock. For Resource UID, see UID.
Exists. Load. Tool safe.