Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script class extending from abstract class is not shown in Create New Node dialog. #93080

Closed
Okxa opened this issue Jun 12, 2024 · 2 comments
Closed

Comments

@Okxa
Copy link

Okxa commented Jun 12, 2024

Tested versions

v4.2.1.stable.arch_linux

System information

Godot v4.2.1.stable unknown - Arch Linux #1 SMP PREEMPT_DYNAMIC Thu, 28 Mar 2024 17:06:35 +0000 - X11 - Vulkan (Forward+) - dedicated AMD Radeon RX 5700 XT (RADV NAVI10) () - AMD Ryzen 9 5950X 16-Core Processor (32 Threads)

Issue description

Any script class created with class_name which extends an abstract class, does not show up on the "Create New Node" dialog, despite extending from abstract class working fine otherwise. (Also might be the same for virtual classes: #58972 because #67614)

In any case, making the script class visible in the dialog is probably preferrable if possible.

Also there are several proposals about allowing to show/hide script classes from the dialog (and not just automatically add them there), here is one: godotengine/godot-proposals#4493

Related (Seems to be about custom nodes added via EditorPlugins): #63536

Steps to reproduce

Create 2 classes, one extending from abstract class, other from normal class. For example using PhysicsBody3D/StaticBody3D:

# 1st class
class_name Test extends StaticBody3D

# 2nd class
class_name NotVisible extends PhysicsBody3D

Results in only the Test class being visible (and able to be created) in the "Create New Node" dialog.

image

Minimal reproduction project (MRP)

mrp-class_name_create_new_node.tar.gz

@Deozaan
Copy link

Deozaan commented Jun 16, 2024

Both classes have the same name. 🤔

@Okxa
Copy link
Author

Okxa commented Jun 17, 2024

Oops, the example code was incorrect, but the MRP (thus the screenshot) had the correct classes.

Also, after digging into, according to #70700, you cannot call new() on script class extending from abstract class:

class MyCanvasItem extends CanvasItem: pass # now ok

func _ready() -> void:
  CanvasItem.new() # now warned as bad, before wasn't
  MyCanvasItem.new() # warned, not allowed
  
  var control := Control.new()
  control.set_script(MyCanvasItem) # ok

Which might be the reason that the node is not visible in the create new node dialog, as I am assuming instantiates the node using new(), thus it cannot be instantiated. The script can be assigned to a node just fine though.

However, it seems that VIRTUAL classes (#58972) can be extended and instantiated, such as basebutton:

GDREGISTER_VIRTUAL_CLASS(BaseButton);

class_name NotVisible extends BaseButton
var test = NotVisible.new()

Note that it is still not visible in create new node dialog, and also not in new script dialog: #84736 and godotengine/godot-proposals#8101

On these grounds, I say this is not an bug on the current implementation, and this issue should be a proposal. (Such as possible to extend abstract classes as non-abstract, or otherwise make changes to the way abstract classes are handled when extending, as it currently is possible to extend from abstract class.)


The actual use case I had was to have a base script extending from PhysicalBody3D, that script is then extended for Static/RigidBody3D etc. node specific behaviour (A script which extends from PhysicalBody3D can be assigned to all of the other nodes inheriting from it).

This real problem would probably be solved with: godotengine/godot-proposals#6416 if it ever gets implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants