Use Mono script metadata also for class->script mapping #27218
Closed
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.
This fixes #27095 by enabling the appropriate CSharpScript's to be reused when the mono module attempts to get a CSharpScript for a given Mono class.
This primarily occurs when one does:
When
new MyNodeSubclass()
is used, Godot will now correctly assign the script "res://MyNodeSubclass.cs" to the newly created Node, instead of assigning a script with an empty path (which will not be saved to the Scene).The script metadata is now kept in-memory in two Map's to enable bi-directional lookup.
The only caveat is that during _update_exports, we need to pre-allocate the native Node before we call the user's constructor. Otherwise the default constructor would call back into C++ to create the native Node, which would trigger a call to
ResourceLoader::load
for the script that is in the process of being created. This would simply fail. If the managed object is already associated with a native object before the constructor is called, this doesn't happen.