How to write custom serializer for a resource?

Godot Version

4.7

Question

I’m creating a custom resource that manages a data buffer (as part of an addon I’m writing). I know that for regular resources, Godot will load and save them by saving each @export marked parameter on them to a stream. However, my custom resource will have some hidden data which is not exposed with @export but which still needs to be saved.

I’d like to write a custom importer/saver, but am unsure the best way to do so. EditorImportPlugin seems to only be for editor plugins. ResourceSaver seems to be for specific file types. I want this to act like a regular resource and just let me override how it’s saved and loaded. What’s the right way to do this?

You can use @export_storage

If you want more control on what and how the data is serialized/deserialized you’ll need to implement the functions Object._get(), Object._set(), and Object._get_property_list() and make the script a @tool script.

Looks like the trick is to use the Object._get(), Object._set() and Object._get_property_list() methods like you suggested, but only have a single property that returns a dictionary. That way you can get the entire group of parameters in one call with lets you provide the validation you need. This is the way the Image class does it too.