Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 6, 2024

Conversation

Maran23
Copy link
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 as a code owner 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
editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
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.
@akien-mga akien-mga merged commit 554c0af into godotengine:master Apr 6, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release topic:editor topic:gdscript
Projects
None yet
4 participants