Open EMBYRDEV opened 1 year ago
After some further testing, any attempt to override CollisionObject3D or PhysicsBody3D in C# results in the following compile error.
[PROJ_PATH]\PlayerBody3D.cs(3,22): error CS1729: 'CollisionObject3D' does not contain a constructor that takes 0 arguments
A CollisionObject3D
is always an area or a body:
Similarly a PhysicsBody3D
always creates a body in one of the pre-existing modes:
So there is little room to extend either in a meaningful way via script. On the other hand it might be neat to have a single script that you could attach either to an area or a body node, though I don't see any obvious use case. In any case, this issue is about scripts extending abstract classes.
- Sounds like a duplicate of C# abstract Godot types missing constructors #55549
It's arguable.
I encountered an issue where I cannot inherit from CollisionObject2D
in C# because it will tell me Cannot access internal constructor 'CollisionObject2D()' here
. Note that CollisionObject2D
is not abstract
.
I'm not sure what is the appropriate way to organize them.
As for the issue itself -- I'll admit I don't have a super solid usecase for inheriting from these classes yet. But I can illustrate a more general usecase maybe.
Godot uses inheritance as a way for your scripts to get access to methods and data from the parent node. If I have something in mind for a script that would work with either CharacterBody2D
or RigidBody2D
or StaticBody2D
I cannot write a single script that inherits from CollisionObject2D
or PhysicsBody2D
and then be able to attach the script to multiple node types, which I think would be a desirable feature.
Godot version
4.0.beta14.mono
System information
Windows 10
Issue description
When in the editor you cannot create a script that inherits from PhysicsBody3D using the new script dialogue.
GDScript files that are manually edited to extend PhysicsBody3D do not immediatly produce any errors but cannot be instantiated.
C# files that extend PhysicsBody3D will not compile due to a missing contructor.
Steps to reproduce
Searching for PhysicsBody3D shows no results.
Searching for CharacterBody3D allows you to inherit from that class however shows both PhysicsBody3D and CollisionShape3D as disabled.
Minimal reproduction project
N/A