godotengine / godotengine/godot-docs
Warn about inability of C# editor plugins to cast to custom C# types that have no `[Tool]` attribute
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**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](https://github.com/godotengine/godot/issues/36395#). Aside from the [general warning about C# being relatively new](https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_basics.html#introduction), 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](https://docs.godotengine.org/en/stable/tutorials/plugins/editor/making_plugins.html#a-custom-node)).
As such, the following example code would only create a custom inspector for class `B`, as that class has the `[Tool]` keyword.
```C#
#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
```
```C#
using Godot;
// Does not have `[Tool]` and does thus NOT show "This instance has a custom inspector"
public class A : Node {}
```
```C#
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):**
- [Making plugins](https://docs.godotengine.org/en/stable/tutorials/plugins/editor/making_plugins.html)
- [C# Basics](https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_basics.html)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.