Fix updating cached singletons when reloading GDScripts #85373
Merged
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.
Fixes #85004
Since
GDScriptLanguage::reload_all_scripts()
is always called when theGDExtension
reload is completed, I decided to update the singleton cache there.I used the original singleton caching code, added a key existence check, and just overwrite the values.
Without
globals.has(E.name)
singletons that were registered viaGDScript
itself or for exampleGDScriptLanguageProtocol
can be added to the cache after theGDExtension
reload and used as the rest of the singletons inGDScript
.#52162 could be fixed if calling
reload_all_scripts
somewhere after loading the editor (there?) and removeglobals.has(E.name)
. I tried updating scripts inEngine::add_singleton
, but it is advisable to do it deferred, andEngine
is a regular class that cannot call methods viacallable_mp
(although it was possible to add a static method and a static boolean variable to prevent multiple calls in one frame). This can be tested in a separate PR, but I'm not really interested in it.It would be cool to merge this before the 4.2 release.