|
|
|
|
Reply From: |
Parv |
ive had the same question myself.
turns out you just need to use the flag FLAG_BUNDLE_RESOURCES
as specified on the docs, because by default the tres/res file will just save a reference to the path of subresources.
so it will look like this:
ResourceSaver.save(path, resource, ResourceSaver.FLAG_BUNDLE_RESOURCES)
also for some reason the opposite load function will not work if you try to cast it like:
var save = ResourceLoader.load(path) as SaveResource
which will return null.
so just use duck typing when loading it back.
Thank you so much, it works!
GameBubby | 2021-12-17 04:06
What do you mean with ducktyping? I can not get any data back from user ResourceLoader.load(path).
voylin | 2022-02-05 06:48
dont try to cast it to your save class when loading since for some reason it will break it.
A bit late, but:
The reason you can’t cast is that bundling resources re-declares that resource locally. Any resource kept in that file is now of type res_file_name_goes_here/res_name_goes_here.tres
, even the very resource of the file itself, and Godot treats the bundled resources and the script resources as completely different objects. So, because you’re trying to cast this bundled resource as a script resource, Godot thinks you’re saying that this apple is an orange, and flips out.
SeaFishelle | 2023-02-08 05:31
Trying to figure this out in Godot 4, but can’t seem to understand it. Would you mind explaining this in more detail?
Currently, I’m saving a resource (player data) with a sub resource (inventory data).
Looking at the saved file in a text editor confirms that I am saving these sub resources,
or at least references of them? (I’m using the flag: FLAG_BUNDLE_RESOURCES).
(I’ll try to provide more detail once I’m next to my computer)
But anyway, upon loading this resource, I get an error saying that the sub class is hiding a script (if I remember correctly, but again, I’ll double check once I’m by my PC).
So I guess the problem is, how do I load a resource which has multiple sub resources nested inside it?
Thanks, and sry for any confusion.
Queble | 2023-03-28 19:56