-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
C#: Add abstract class support #81101
C#: Add abstract class support #81101
Conversation
dfe425f
to
e36542e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! I've been meaning to add proper support for abstract classes to C#.
This is a review of the code only, I haven't had a chance to build and test it yet.
modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs
Outdated
Show resolved
Hide resolved
e36542e
to
28d8003
Compare
28d8003
to
bad9c81
Compare
bad9c81
to
ae3716b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have built and tested the PR and looks great, but the inspector's resource picker still lets you choose abstract classes. You'll have to modify EditorResourcePicker
to ignore abstract classes so they don't show up:
godot/editor/editor_resource_picker.cpp
Line 512 in bc88dca
if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instantiate(t))) { |
However, it has crossed my mind that maybe we should change ClassDB::can_instantiate
instead, so it considers abstract global classes non-instantiable. The related PR #67777 makes similar changes but it changes ClassDB::is_virtual
.
#67777 seems to make a claim about If that ends up being desirable, I wonder if it would be beneficial to move these kinds of checks on global classes to a new |
917cdd5
to
e012227
Compare
I think this may be because GDScript I'm not sure what would be the correct changes to make to So, maybe Adding a similar change to
That sounds reasonable to me if it can simplify some of these checks. I'd like to know the opinion of others as well, but yeah it's out of scope for this PR and can be done in a follow-up. |
Sounds good. I'll write those ideas down for future PRs. I went ahead and added the check to |
e012227
to
22eea04
Compare
Forgot to expose |
22eea04
to
4397597
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I tested it and works as expected. Needs a rebase after #80184.
a31f0cd
to
90835ce
Compare
90835ce
to
92848e1
Compare
It's better the way it is now, since we don't want to present creating virtual/abstract classes to the user. This is the entire purpose of marking it as virtual/abstract. Whether it can be technically instantiated on the C++ or C# side is a secondary concern, we do of course want those to be forbidden too, but CreateDialog needs to consider more than that.
|
Since this PR goes a bit further than just Plus, there are some changes I've made regarding the GDExtension implementation and a few I would certainly love to see what others think, though.
To add onto what @aaronfranke mentioned, |
I didn't test, but the GDExtension code in this PR looks good to me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good on my side, but make sure both the GDScript and Mono teams approve.
92848e1
to
0e56ad4
Compare
Rebased after #81487. |
0e56ad4
to
2df37a2
Compare
I realized it may be beneficial to add an error message to |
Just want to clarify, is GDScript approval necessary here? Afaik the only change I made there is a basic one-line override of |
Thanks! |
At the moment, Godot internally does not support abstract scripts. This poses an issue when trying to create abstract classes in languages such as C#, because it has no way of knowing that trying to instantiate an abstract class is an invalid operation.
Abstract scripts appearing in the create dialog can no longer be instantiated as is the case with built-in classes such as
CanvasItem
. This also allows global abstract classes to remain untouched and functional. Furthermore, non-global C# classes no longer throw an error about an empty inheriting script path.