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

Changing name of script after using it in preload() generates "Could not resolve script" error, recoverable only by reloading project #92007

Open
mirage3d opened this issue May 16, 2024 · 1 comment

Comments

@mirage3d
Copy link

Tested versions

v4.3.beta.custom_build [557f63d]

Custom build for the precision=double flag

System information

Godot v4.3.beta (557f63d) - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Ti Laptop GPU (NVIDIA; 31.0.15.3598) - AMD Ryzen 7 5800H with Radeon Graphics (16 Threads)

Issue description

Using a script's path in a const XXX := preload() function, and then renaming the script using Godot's "Rename" menu command, gives a "Error at (xx, yy): Could not resolve script "res://script_name.gd".

The error persists even after retyping the expression. Using "=" instead of ":=" also does not make the error go away. Renaming the script back and using the old name in preload() also does not resolve the issue.

It's undoable. Gives vibes of "Anton Chigurh" in "No Country for Old Men".

Steps to reproduce

  1. Create any script. e.g. "script_a.gd".
  2. In another script, load the first script into a const using preload(). e.g. const ScriptA := preload("res://script_a.gd").
  3. Rename the first script's name. e.g. "script_b.gd".
  4. Error appears in the second script.
  5. Edit the name in the preload() function, rename the first script to original name, close and reopen the second script, and try a few other things, but the error persists.
  6. Reload project, error gone.

Minimal reproduction project (MRP)

The steps above to reproduce the issue are sufficient to display the problem, and no MRP is needed.

@akien-mga
Copy link
Member

akien-mga commented May 16, 2024

I can reproduce the issue on Fedora 40 with 4.3.beta (5708a3a).

After renaming the first script, and saving the one with preload, this error is printed, somewhat expectedly:

res://main.gd:3 - Parse Error: Preload file "res://script_a.gd" does not exist.
res://main.gd:3 - Parse Error: Cannot infer the type of "ScriptA" constant because the value doesn't have a set type.

At this step:

Edit the name in the preload() function, rename the first script to original name, close and reopen the second script, and try a few other things, but the error persists.

  • Editing the name in the preload() function to match the new name complains that it couldn't resolve res://script_b.gd.
res://main.gd:3 - Parse Error: Could not resolve script "res://script_b.gd".
res://main.gd:3 - Parse Error: Cannot infer the type of "ScriptA" constant because the value doesn't have a set type.
  • Renaming the first script to script_a.gd (while keeping that name in the preload call) also doesn't solve the issue, and prints these errors:
Attempt to open script 'res://script_b.gd' resulted in error 'File not found'.
res://main.gd:-1 - Compile Error:

Occasionally it does seem to resolve the error after printing this once.


In 4.2.2-stable, the issue seems similar, though I had to do explicit changes to the scripts to start catching errors, while in 4.3.beta just saving the script without modification was enough.


Note: On 4.3.beta on Linux, when renaming a script in the FS dock, I get this error:
image
But I don't think it's related to this issue, it's a regression similar to #90473.

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

No branches or pull requests

2 participants