Automatically Bundling Subresources

Godot Version

v4.4.1.stable.official

Question

Hello, everyone!

Is there a way to ensure that a resource has all of its subresources bundled within the resource? If necessary, I don’t mind having to implement a runtime solution.

For example, let’s say that I’ve made a scene with a cube and texture it with an image that’s external to the scene — I would like to ensure that the image is automatically made local to the scene (perhaps through automated copying).

For context, I’m working on a scene that automatically saves a resource and its subresources to a file, supposedly allowing one to then load the file later. I’ve been trying to use a ResourceSaver with ResourceSaver.FLAG_BUNDLE_RESOURCES to bundle the external resources, but it keeps relaying Broken external resource! (index out of size). This problem, however, does not occur when the subresources are saved locally into resource, but I would like to avoid doing that manually.

It could be interesting to investigate why ResourceSaver.FLAG_BUNDLE_RESOURCES doesn’t seem to do what it advertises, but that’s outside of the scope of this post. I could’ve just misunderstood its purpose, or perhaps one would have to manually extend external_resources here, though I wouldn’t know how to do that.

Thank you for your time.

I was able to resolve this in runtime by getting the resource’s dependencies with ResourceLoader.get_dependencies and putting them in a ZIP alongside the resource, where I would then unpack the ZIP and its components later.