godot
godot copied to clipboard
Error message asked me to make an instance of TextServer
Tested versions
4.2.2
System information
Pop!_OS 22.04 LTS - X11 - Vulkan (Forward+) - integrated Intel(R) Graphics (ADL GT2) () - 12th Gen Intel(R) Core(TM) i5-1235U (12 Threads)
Issue description
var shaped_text_rid := TextServer.create_shaped_text()
I wrote this and I got this loony error asking me to create an instance of TextServer: "Cannot call non-static function "create_shaped_text()" on the class "TextServer" directly. Make an instance instead."
I know this isn't correct, but the error message for sure was wrong and it took me a while to work out the problem.
Steps to reproduce
Use the above line of code.
Minimal reproduction project (MRP)
N/A
The error doesn't seem wrong to me. TextServer isn't a singleton, and the method isn't static, so it can be called like this.
I'm not familiar with using it but from a quick look, there seems to be a TextServerManager singleton, and its get_interface() method should give you a TextServer instance.
I assume you found it confusing because other *Servers tend to be singletons?
CC @bruvzg
Ooh, I see. The confusion came from the fact that TextServer is an abstract class, and you're expected to make an instance of it, which actually means you're are expected to make an instance of the inheriting classes (in this case, typically TextServerManager.get_primary_interface()).
Should we close this then?
You can get an active text server instance using TextServerManager.get_primary_interface(), but in most cases you should prefer TextParagraph/TextLine/Font classes instead of using text server directly.
I think these points would be worth clarifying in the description of TextServer in the docs.
To clarify, what confused me is how the error asked me to instantiate a TextServer, when it's actually an abstract class that can't be instantiated, and you're meant to instantiate inheriting classes. I thought TextServer was a singleton, like the other servers I've had to use before.