Hi all, I'm running into a serialization issue while working on some raytraced effects in my game. I'm calculating a lot of GPU-ready acceleration structures in the editor so they don't need to be processed at runtime and figured I would store the final results as PackedByteArrays inside a Resource class for ease of implementation with quick enough load times.
I first noticed this approach behaving oddly when the arrays were listed as "size 0" while inspecting the saved resources in the editor, but the files were large enough they clearly contained the data, and it was loading it from disk fine when launching the game. I wrote it off as a visual bug. Now that it's come time to test in an export, however, I'm finding that the arrays truly are empty when inside of my PCK. No, this is not a path issue, I'm using the Godot Resource Groups addon by Godotneers, and it is loading the resources & finding the one I'm looking for successfully. It's just the PackedByteArrays are empty. Every single file is 132 bytes (instead of tens of KB) according to GodotPCKExplorer, printing the size of the node and triangle arrays reveals they are 0.
Is there something I'm doing wrong when saving the file, or is there an issue in the engine with serializing this datatype? Is there an alternative way I could save/load the bytes, such as https://docs.godotengine.org/en/stable/tutorials/io/binary_serialization_api.html#packedbytearray? (Unclear to me if this is already used behind the scenes by the ResourceSaver class)
Thanks in advance!
The entire code for the resource I'm trying to save to disk:
class_name PackedBVH extends Resource
@export var md5: String = ""
@export var mesh_resource_path: String = ""
@export var nodes: PackedByteArray = []
@export var triangles: PackedByteArray = []
The code relevant to saving the resource to disk, which runs in a @tool script after checking Engine.is_editor_hint():
var md5: String = mesh.resource_path.md5_text()
var packed_resource_path: String = "res://resources/rt/packed_bvh_data/packed_" + md5 + ".res"
...BVH generation code...
var packed_bvh: PackedBVH = bvh.pack()
ResourceSaver.save(packed_bvh, packed_resource_path, ResourceSaver.FLAG_COMPRESS)
Images:
- The file system tab showing the saved resources and their sizes
- The inspector showing the PackedByteArrays are size 0
- The files being only 132 bytes in GodotPCKExplorer
- Debug output of loading when running the game in the editor
- Debug output of loading when running the standalone export