godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.01k stars 21.17k forks source link

C# Custom RichTextEffect Not in Dropdown #96665

Closed SomethingFawful closed 2 months ago

SomethingFawful commented 2 months ago

Tested versions

System information

Godot v4.3.stable.mono - Ubuntu 22.04.4 LTS 22.04 - X11 - Vulkan (Forward+) - dedicated NVIDIA RTX A2000 Laptop GPU - 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz (16 Threads)

Issue description

Creating a Rich text effect by extending the RichTextEffect class, setting the bbcode string and overriding the _ProcesssCustomFX, and the [Tool] and [GlobalClass] annotations does not show up in the drop down in editor, while ones created in GDScript do. Using InstallEffect() in a C# script to add the effect works correctly.

Steps to reproduce

  1. Load the example project
  2. Open control.tscn
  3. Look at the Custom Effects property of the RichTextLabel
  4. Note that only RichTextGDScript is an option, RichTextTest (written in C#) isn't.
  5. Run the project
  6. Note that after adding manually in the C# script, the custom tag displays correctly.

Minimal reproduction project (MRP)

RichTextEffectsBug.zip

raulsntos commented 2 months ago

I looked at the provided MRP, and the class RichTextTest is in a file named NewScript.cs. This makes the script invalid, the name of the file must match the name of the class. So rename the file to RichTextTest.cs or the class to NewScript.

This and some other gotchas are documented in the C# basics documentation page.

For attached scripts, we would normally print an error in the console when trying to instantiate the invalid script. But since this script is not attached or instantiated anywhere, it won't show an error.

SomethingFawful commented 2 months ago

This is what I get for being lazy when making my MRP (although that doesn't explain why I could use it when running the project)... which does fix the issue (although now I'm wondering what I did wrong in my main project because I did have the name right there)... we can close this one, although I'll be making a documentation update PR later to add C# working examples.