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

C#: CSharpScript.CanInstantiate() returns true for abstract classes but .New() throws at runtime #78244

Closed
juse4pro opened this issue Jun 14, 2023 · 4 comments · Fixed by #81101

Comments

@juse4pro
Copy link

Godot version

v4.1.beta1.mono.official [828ec2c]

System information

Windows 11

Issue description

When I call .CanInstantiate() on a CSharpScript object it returns true even though it can't be instantiated via .New() when the class is abstract. I get a runtime exception: MemberAccessViolation: Cannot create an abstract class. (see attachment)
image

I would expect that .CanInstantiate() only returns true when I actually can instantiate it.

Steps to reproduce

  • Get some kind of CSharpScript (e.g. via ResourceLoader)
  • Call .CanInstantiate() on it / print it
  • Call .New() on it
  • Get exception

Minimal reproduction project

CanInstantiateBug.zip

@AThousandShips
Copy link
Member

The script system doesn't seem to have any concept of abstractness, and the function doesn't test anything like that in CSharpScript, so seems like a missing functionality, would be supported if abstract classes were added to GDScript probably:

@RedworkDE
Copy link
Member

Also IIRC there was an issue for pretty much the same thing with gdscript where for core types can_instantiate returns true, but it is not actually possible to do so, can't find it rm tho,

@AThousandShips
Copy link
Member

Was it:

@juse4pro
Copy link
Author

I can understand that GDScript does not support the concept of abstraction yet. But to be honest when a method says Returns true if the script can be instantiated. but I can't instaniate it I would expect that the CSharpScript implementation overrides it in a way that the abstract marking is checked. Because this way the API just delivers a wrong information.

So I think it more a bug seen from this perspective.

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

Successfully merging a pull request may close this issue.

5 participants