#PackedByteArray not saving as part of Resource when in exports?

1 messages · Page 1 of 1 (latest)

tame sleet
#

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:

  1. The file system tab showing the saved resources and their sizes
  2. The inspector showing the PackedByteArrays are size 0
  3. The files being only 132 bytes in GodotPCKExplorer
  4. Debug output of loading when running the game in the editor
  5. Debug output of loading when running the standalone export
real rover
#

I had a similar problem with my @exported custom typed array

tame sleet
#

also still 132 bytes exactly

#

might be because i'm already saving them as binary

#

fwiw when i save it as a .tres i can see the packedbytearray getting set to a huge base64 string but it's still broken in the inspector and exports

#

ok i figured out the 132 byte files are remaps pointing to another spot, but i extracted the actual files and they're still tiny and missing all the PackedByteArray data

#

weirdly it seems like that toggle didn't do anything for the export even after saving them as .tres files

#

the .tres (230KB) in my project vs the .res in my exported .pck (560B) (i know i'm opening a binary file in a text editor but like clearly the byte array data is just disappearing at some point)

latent harbor
#

This seems like it might be @tool shenanigans. I'm not certain this is the issue in this case, but sometimes custom resources need to be tagged as tools in order to interact properly with tool scripts in the editor.
Also, ResourceSaver.save() returns an Error, I'd suggest checking to see if it's Error.Ok

#

FileAcess.store_var() and .load_var() both serialize a variant to binary, which includes basically any engine type including packed arrays. While I'd also try to use resources in this case, if needed you can just manually write/read the relevant data to a file.