I did find a solution:
- When you load resource from disk, it will have its and all of its subresources'
resource_path
set to this file.
- When you make some changes and try to load resource again, Godot looks at subresources'
resource_path
and goes "Its the same resource! I'm just going to use the version I already have in memory"
- So what we need to do is call
take_over_path("")
on our resource and all of its subresources. This will set resource_path
to ""
and now Godot will load everything exactly like it is stored on disk.
A good time to call take_over_path
is immediately after loading the resource from disk. This has to be done either manually for each subresource, and their subresources, or you can for example write a recursive function like clear_cache(resource)
that:
- Calls
resource.take_over_path("")
- Iterates over
resource
's fields
- If field is a resource, calls
clear_cache(field)
- If field is an array or dictionary or something, calls
clear_cache
for each its element that are a resource
A problem may arise if you have resources that reference each other, which will result in an infinite loop. From the top of my head this could be fixed by adding step 0: check if path is already ""
, if so return. This may possibly lead to some other problems along the way though.
I personally went the manual route instead since I needed to work with subresources manually anyway, for resource duplication reasons.