godot-docs
godot-docs copied to clipboard
Warn about inability of C# editor plugins to cast to custom C# types that have no `[Tool]` attribute
Your Godot version: v3.4.4.stable.mono
Issue description:
As a different issue already indicates: Mono editor plugins can't cast non-tool C# types. Aside from the general warning about C# being relatively new, there does not seem to be any mention in the documentation that a class needs to be marked as [Tool] to have a custom inspector in C# (and might even suggest it is optional, albeit in a different context).
As such, the following example code would only create a custom inspector for class B, as that class has the [Tool] keyword.
#if TOOLS
using Godot;
public class ABInspectorPlugin : EditorPlugin
{
public override bool CanHandle(Object @object)
{
return @object is A || @object is B;
}
public override void ParseBegin(Object @object)
{
AddCustomControl(new Label { text = "This instance has a custom inspector" });
}
}
#endif
using Godot;
// Does not have `[Tool]` and does thus NOT show "This instance has a custom inspector"
public class A : Node {}
using Godot;
[Tool] // Does show "This instance has a custom inspector"
public class B : Node {}
Most pages about writing editor plugins do however warn about adding the [Tool] attribute due to the risks associated with running some code in the editor; which is understandable. Lack of visibility of the aforementioned limitation, and warnings against the [Tool] attribute could lead developers to waste some time figuring out why their custom inspector won't show up.
I'm not sure whether, and if so how, 4.X will change this. But Is suppose documenting this limitation for the current version should suffice in the meantime.
URL to the documentation page (if already existing):