godot-cpp
godot-cpp copied to clipboard
Nodes inheriting from abstract classes do not show up in the "Create New Node" menu
When I have a node type that extends CanvasItem, CollisionObject(2D/3D), Joint(2D/3D), or Light(2D/3D), and register it with ClassDB::register_class
, the node does not show up in the "Create New Node" menu. However, the same node works if I change it to inheriting Node, Node2D, etc. This is a necessary feature if we want GDExtension to have the same feature set as the engine, so that people can make their own custom classes inheriting these abstract types (as I wish to).
I noticed the same for resources. Resources inheriting from abstract classes also are missing from the "Create New Resource" menu. Not just missing from the menu, but also displaying MissingResource when trying to open files containing these resources.
I found that ClassDB::register_abstract_class is not working correctly, First, I tried to register virtual class (by ClassDB::register_abstract_class) which has a pure virtual method, but encountered with compile error, so i had to change pure virtual class to virutal class with fake return value. Second, I implemented several classes with inherited from virtual classes, but when turn off the editor, unregister process is not working correctly.
here is when the editor turned off.
And If I register any classes by register_abstract_class, the class and its child classes / nodes are not visible in "Create New Node" menu. So i had to all virtual class registered by not register_abstract_class, but register_class.
For CanvasItem, this requires https://github.com/godotengine/godot/pull/67510 to be merged into the engine.
Confirming this, extending from Viewport will report
Extension class Foo cannot extend native abstract class Viewport
Closing because this is working as intended, the intention is that you are not allowed to extend abstract types. See the reasoning here: https://github.com/godotengine/godot/pull/67510#issuecomment-1959194590