Prevent instantiating classes that aren't exposed #102440
Open
+2
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Originally from #99534
Currently, if you call
ClassDB::can_instantiate("...")
for an internal class, it will returntrue
, but most normal ways of instantiating the class in GDScript, GDExtension or C# won't work. However, they still can be created via viaClassDB::instantiate("...")
. There's also no indication to GDExtension or scripting fromClassDB
that these classes can't be instantiated normally because we don't exposeClassDB::class_is_exposed()
.For example:
Do we even want internal classes to be instantiatable via
ClassDB::instantiate("...")
?This PR answers no, and makes it so that internal classes return
false
forClassDB::can_instantiate()
and can't be created viaClassDB::instantiate("...")
.I don't think there's anything that depends on the old behavior, but I'm not 100% sure, so treat this one with caution.