Skip to content

Fix errors when renaming/moving/deleting global scripts#90186

Merged
akien-mga merged 1 commit intogodotengine:masterfrom
Maran23:error-when-rename-move
Apr 6, 2024
Merged

Fix errors when renaming/moving/deleting global scripts#90186
akien-mga merged 1 commit intogodotengine:masterfrom
Maran23:error-when-rename-move

Conversation

@Maran23
Copy link
Copy Markdown
Contributor

@Maran23 Maran23 commented Apr 3, 2024

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:

  • Attempt to open script 'xxx' resulted in error 'File not found'.
  • Failed loading resource: xxx. Make sure resources have been imported by opening the project in the editor at least once.
  • Parser Error: Class 'xxx' hides a global script class.

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:

  • Attempt to open script 'xxx' resulted in error 'File not found'.
  • Failed loading resource: xxx. Make sure resources have been imported by opening the project in the editor at least once.
    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'.

@Maran23 Maran23 requested a review from a team April 3, 2024 23:23
@akien-mga akien-mga added bug topic:editor cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Apr 4, 2024
@akien-mga akien-mga added this to the 4.3 milestone Apr 4, 2024
@Maran23 Maran23 force-pushed the error-when-rename-move branch from 30b4984 to 7d22d07 Compare April 5, 2024 16:39
When renaming or moving global scripts, the following errors can appear:
- Attempt to open script 'xxx' resulted in error 'File not found'.
- Failed loading resource: xxx. Make sure resources have been imported by opening the project in the editor at least once.
- Parser Error: Class 'xxx' hides a global script class.

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:
- Attempt to open script 'xxx' resulted in error 'File not found'.
- Failed loading resource: xxx. Make sure resources have been imported by opening the project in the editor at least once.
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 / correctly know what the user just did.
@Maran23 Maran23 force-pushed the error-when-rename-move branch from 7d22d07 to dda06a8 Compare April 5, 2024 16:52
@akien-mga akien-mga merged commit 554c0af into godotengine:master Apr 6, 2024
@akien-mga
Copy link
Copy Markdown
Member

Thanks!

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

Projects

None yet

4 participants