godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.12k stars 21.19k forks source link

Duplicating a script causes the current script to display wrong UID #87580

Open KoBeWi opened 9 months ago

KoBeWi commented 9 months ago

Tested versions

4.3 4b6ad34

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 30.0.15.1403) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

When you duplicate a script and the original script is currently opened in the script editor, its UID will change and will be the same as UID of the new script. The bug is purely visual for some reason. When you open the script in external editor, you'll see that it has the old UID and it's different from the new script. The script in editor fixes itself after you save it or switch tab a couple of times. It does not happen if the script is not currently opened in the editor.

Steps to reproduce

  1. Create a GDScript
  2. Open it in the script editor
  3. Duplicate the script
  4. Open the new script
  5. Notice that both scripts have the same UID
  6. It's a lie

Minimal reproduction project (MRP)

N/A

FantasmaGolicon commented 9 months ago

Been looking at this for the past couple days. I believe it has been temporarily resolved by https://github.com/godotengine/godot/pull/87712 since the UIDs for scripts got reverted.

For anyone looking at this in the future - The origin Resource is being updated in the saver with the contents of the newly created script, which includes the newly generated UID. The Script Editor reloads the text from the Resource in memory, not from disk.

The script gets reloaded when Godot comes back into focus from an external application. Pressing reload will refresh the resource to match with the version in disk.

I modified the code in filesystem_dock to duplicate the origin resource and save it to the new path instead of re-using the origin Resource. That did the trick

However, this may not be needed since adding UID to gdscript is still not fully defined