godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Nodes inheriting from abstract classes do not show up in the "Create New Node" menu

Open aaronfranke opened this issue 2 years ago • 3 comments

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).

aaronfranke avatar Sep 29 '22 03:09 aaronfranke

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.

EngineGuy avatar Nov 06 '22 00:11 EngineGuy

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. image

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.

timetravelCat avatar Jun 11 '23 04:06 timetravelCat

For CanvasItem, this requires https://github.com/godotengine/godot/pull/67510 to be merged into the engine.

aaronfranke avatar Jun 11 '23 05:06 aaronfranke

Confirming this, extending from Viewport will report Extension class Foo cannot extend native abstract class Viewport

CherrySodaPop avatar Feb 25 '24 00:02 CherrySodaPop

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

aaronfranke avatar Feb 25 '24 00:02 aaronfranke