• ResourcesGodot 4.X
  • Is it possible to update a resource directly from (an external) code editor?

Using an external code editor (in my case Visual Studio), I love that I can can update the code and run the game directly (without having the Godot editor opened).
However, when I do something in the code editor that updates a resource used in the game (such as replacing an image), the update isn't reflected once I run the game...

Is there anyway to get the game to update it's resource cache externally (without opening the Godot editor)? I'm not trying to use a Tool script (since those only run inside the editor)?

I tried to use the ResourceSaver in runtime to update the resource, but I don't quite know how to (or if it's only meant to be doon in TOOLS scripts...
Is it possible to pass along an argument when starting the game to invalidate the cached resources?

Thanks

  • xyz replied to this.

    kloot I don't think resources are cached between runtimes. When you start the game all resources should be loaded anew from the files. Maybe there's something else in your code that's causing the problem. Can you reproduce it in a minimal project?

      xyz As I understand it they are stored as resources (under the .godot folder). Updating the image on disk between runs doesn't work unless you first open the Godot editor (which updates the resource).

      • xyz replied to this.

        kloot You can delete the corresponding file(s) in .godot/imported

        But that's not a png file, but a .ctex-file (with a corresponding md5-file). I don't mean to change how it was once imported, I just want to use APIs such as ResourceLoader and ResourceSaver to refresh the resource based on the resource path somehow (res://MyImage)...

        • xyz replied to this.

          kloot Those file are "the cache". So when you change the png and delete the import files, it should force re-importing of the png. Btw can you post the exact code and steps you're doing?

            kloot Also, have you tried changing the cache mode when calling ResourceLoader::load()

            xyz

            Also, have you tried changing the cache mode when calling ResourceLoader::load()

            I tried calling this in runtime - does nothing:

            ResourceLoader.Load("res://MyImage.png", null, ResourceLoader.CacheMode.Replace);
            ResourceLoader.Load("res://.godot/imported/MyImage.png-e50e3f880ea2b769c7af2908269b6084.ctex", null, ResourceLoader.CacheMode.Replace);

            Thanks for looking into this, if you want to reproduce the issue:

            1. Create a new Godot project with a default scene that has a Sprite node (showing a texture like res://Image.png)
            2. Close the Godot editor and now run the project from an external code editor - note that Image.png is displayed correctly
            3. Now change the content of Image.png (using Photoshop/Gimp to edit the Image.png directly on disk)
            4. Now try running the project from the code editor once more- note that the old PNG is still showing

            I tried deleting the .ctex/.md5/.png.import files (I tried all combinations), the only result is that the PNG isn't shown in game.

            I wonder if there is a way to get the game to refresh the cache of the image, either in runtime or by passing a parameter when the game is started or something similar...

            Hm, you're basically asking for runtime re-import. I don't think this is currently possible in a straightforward way. It was discussed on github. Imports can apparently be updated only by the editor (and directly messing with files, bypassing ResourceLoader completely, which is probably painful). I also haven't seen any command line options that could force this without invoking the editor.

            As a compromise you can try making an additional command in your external editor (call it "update imports") that runs the project with --editor --quit flags. This will open it in the Godot editor and quit immediately, which should trigger the reimport of updated resource files. Haven't tried it but in theory it should work.