How to use Tool for assist but not to break the entire component?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By IlyaChernikov

I need a Node2D component that draws a rect visible only in the editor viewport. I tried to use a CollisionShape2D but it shows ugly yellow exclamation mark icon because it has improper parent. I made it just a Node2D type and wanted to draw a rectangle myself. After I marked my class with [Tool] attribute, everything broke because there was runtime-related logic in _Ready() function. The only solution I found is to use editor check guard if (Engine.IsEditorHint()) return; but it is an ugly solution for this task.
I tried to subclass my component from a tool class but it doesn’t work, probably not getting correctly registered in engine’s internal logic. Is there a convenient way to define an additional (decorating) logic to an existing component and not break the component. Mixing up tool and runtime code seems a very bad solution, IMO

:bust_in_silhouette: Reply From: Moreus

There is official Running code in the editor — Godot Engine (stable) documentation in English ,
not sure why is ugly :wink:
you can manually start _Ready() or make new metod with required content and make sure is run only once.
If you share your code we could suggest more :wink:

:bust_in_silhouette: Reply From: Wakatta

You’re trying to create what already exists.

Its called a ReferenceRect node and also has an Editor only option