Fix errors when renaming/moving/deleting global scripts #90186
Merged
+48
−6
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: #67056
Fixes: #81867
Fixes the root cause in (but there is also some discussion about regnerating the script cache): #78642
When renaming or moving global scripts, the following errors can appear:
When deleting scripts, errors appear when opening the 'Create Node Dialog' as the script cache still contains the removed global scripts. The following errors can appear:
editor/create_dialog.cpp:241 - Condition "scr.is_null()" is true.
All this errors can be fixed by correctly handling the cases. They involves removing the old path and adding the new one (if not deleted) to the ScriptServer. This is somewhat similar if the file is moved or deleted outside Godot and detected by the file watcher, but more specialized for this particular usecase, since we know the old and the new path / know what the user just did.
You can verify this in the following Test Project:
MoveClass.zip
Just move the
CScript.gd
file around and start the game. You will eventually get the error mentioned above without this patch.You can also delete the folders and verify, that there will not be any error when opening the 'Create Node Dialog'.