#BlobReference not containing assigned values in BlobArray

1 messages · Page 1 of 1 (latest)

hollow cradle
#

I'm creating a blob for mesh generation information which contains an array of face texture indices, however after adding the array to the blob and creating the blob reference, the array is empty yet all other information is correct. I check before and after constructing the array into the blob but then the array is empty once I create the blob reference and attempt to access the array.

This is my first time working with Blob assets and am probably doing something obvious, thank you for any aide.

// build new blob
var builder = new BlobBuilder(Allocator.Temp);

int oldLength = _currentBlob.IsCreated ? _currentBlob.Value.Data.Length : 0;
int newLength = BlockRegistry.GetLength();

ref var root = ref builder.ConstructRoot<BlockDatabaseBlob>();

var blocks = builder.Allocate(ref root.Data, newLength);

// copy old data
for (int i = 0; i < oldLength; i++)
    blocks[i] = _currentBlob.Value.Data[i];

// append new data
for (int i = 0; i < _newlyAddedBlocks.Count; i++)
{
    ushort id = _newlyAddedBlocks[i];
    var data = BlockRegistry.GetData(id);
    ref var block_root = ref builder.ConstructRoot<BlockDatabaseInfo>();

    block_root.texture_format = data.texture_format;
    var texes = builder.Construct(ref block_root.face_textures, data.face_textures);
    // logs "6"
    Debug.Log(texes.Length.ToString());

    blocks[id-1] = block_root;
}

// create new blob
BlobAssetReference<BlockDatabaseBlob> newblob =
    builder.CreateBlobAssetReference<BlockDatabaseBlob>(Allocator.Persistent);

builder.Dispose();

// swap references
_currentBlob = newblob;

// logs "0"
Debug.Log(_currentBlob.Value.Data[0].face_textures.Length);

I am unable to set the block_root.face_textures to the return value of builder.Construct and builder.Allocate seemingly doesn't work either.

fervent spear
#

builder.ConstructRoot
is questionable - constructroot is generally only used once per builder being it's just for the root struct

#

what you're probably looking for here is
ref var block_root = ref blocks[id-1];