What data is saved from a custom Resource into a .tres file, and how?

Godot Version

4.3.stable

Question

G’day!

I’m working on a simplified open-world system for my project, and I’m aiming to use custom Resources to save data about the world in chunks. This way, instead of needing to load PackedScenes with hundreds or thousands of nodes for things off in the distance I can just use a resource to tell me what data I should send to the RenderingServer directly. The problem is that I don’t know much about Resources.

I want to write a script to create and edit these chunk Resources in the editor, but I’m struggling to find good documentation on exactly how this works. All the examples I can find just use exported variables that are changed in the editor. For my purposes I’ll need something like an array that I can append other resources to, and I’ll need to be able to edit this data and overwrite a specific saved resource that already exists on the disk.

Is that how resources work? When I make my custom resource class (extends Resource) can i just make a non-exported array a property of that class, write a function that appends to that array, then in code load the resource and call the appending function? Will that change the .tres file and the data it stores? Or am I going about all this the wrong way and should just use a .json file or something?

Any and all help would be greatly appreciated, thank you!

Saving resources actually requires @export on members, non-exported variables will not be saved. You can @export any kind of data, including arrays.

Maybe a binary FileAccess system will serve you better, depends on what data you want to store in each chunk.

1 Like

Thank you! Yeah I can’t really get away with using exported variables since I want to write a tool to automate saving the data, and as far as I can tell there’s no good way to edit an exported variable with code.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.