#Skyrbunny does not understand Blobs

1 messages · Page 1 of 1 (latest)

sweet lava
quiet cliff
#

Look at BloblificationTests

#

it shows how you can construct BlobAssetReferences

#

in FlattenBehaviours you're using a BlobBuilder

#

but you're not creating the BlobAssetReference

sweet lava
#

I understand that part but I'm trying to do something a little different I think. Im trying to construct a struct that has blob arrays as parameters

#

wait. so as parameters, should I be using blobassetreferences?

quiet cliff
#

Yea and it needs to live in a BlobAssetReference

sweet lava
#

hmm so I need to rewite... all of this...

quiet cliff
#

i think this does a decent job describing the workflow

sweet lava
#

oh so if I have multiple blobs that have some of the same parameters, it will auto-de-duplicate it... nice

#

so if I wanted to make a BlobAssetReference that was an array, how would I do that?

ref var blobAsset = ref blobBuilder.ConstructRoot<BlobArray<FixedString32>>(); //create new asset
var array = blobBuilder.Allocate<BlobbableRawStruct>(ref ???, 1); //What do I do here?
array = inArray; //???
quiet cliff
#
            var builder = new BlobBuilder(Allocator.Temp);

            ref var root = ref builder.ConstructRoot<GlobalLayerMask.Rules>();
            var maskArray = builder.Allocate(ref root.MaskRules, Matrix.LayerRules.Length);
            
            fixed (int* ptr = Matrix.LayerRules) {
                UnsafeUtility.MemCpy(maskArray.GetUnsafePtr(), ptr, 4 * Matrix.LayerRules.Length);
            }

            var blobAsset = builder.CreateBlobAssetReference<GlobalLayerMask.Rules>(Allocator.Persistent);
            builder.Dispose();

            conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref blobAsset);
            dstManager.AddComponentData(entity, new GlobalLayerMask { Value = blobAsset });
#

something like this

#

this is how i construct my collision rules and luckily it just only has an array

sweet lava
#

ooh, okay. hang on

#

so something like

#
    public static BlobAssetReference<BlobArray<T>> ConvertArrayToBlob<T>(T[] inArray)
    {
        using var blobBuilder = new BlobBuilder(Allocator.Temp); //new builder
        ref var builtBlobArray = ref blobBuilder.ConstructRoot<BlobArray>(); //create new asset
        //Allocate and populate array
        var arr = blobBuilder.Allocate<BlobbableRawStruct>(ref builtBlobArray, inArray.Count);
        arr = inArray;
        //Create blob asset reference
        BlobAssetReference<BlobArray<T>> blobAsset = blobBuilder.CreateBlobAssetReference<BlobArray<T>>(Allocator.Persistent);
        blobBuilder.Dispose();
        return blobAsset;
    }

quiet cliff
#

yea

#

looks right

sweet lava
#

okay cool. ints dont need to be blobassetreference right

quiet cliff
#

yea sorry, you don't need them to be in a blob pointer or anything

#

they can remain as fields

sweet lava
#

ok cool

quiet cliff
#

but it would mean that when you do a local copy, it would copy the values over

sweet lava
quiet cliff
#

where T : unmanaged

sweet lava
#

ref var builtBlobArray = ref blobBuilder.ConstructRoot<BlobArray<T>>(); gived me error ConstructBlobWithRefTypeViolation: You may not build a type BlobArray 1 with Construct as BlobArray 1[] is a reference or pointer. Only non-reference types are allowed in Blobs.. huh???

quiet cliff
#

you can't construct a root like that

#

it's a bit weird

#

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

#

GlobalLayerMask.Rules is a struct

#
public struct S {
  public BlobArray<some_primitive_type> Values;
}

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

this is why I say the BlobificationTests is a good reference

#

they pretty much show you the set up

sweet lava
#
struct S<T> where T : unmanaged
    {
        public BlobArray<T> Value;
    }

public static BlobAssetReference<BlobArray<T>> ConvertArrayToBlob<T>(T[] inArray) where T : unmanaged
    {
        using var blobBuilder = new BlobBuilder(Allocator.Temp); //new builder
        ref var builtBlobArray = ref blobBuilder.ConstructRoot<S<T>>(); //create new asset
        //Allocate and populate array
        var arr = blobBuilder.Allocate<T>(ref builtBlobArray.Value, inArray.Count());

        int i = 0;
        foreach (var item in inArray)
        {
            arr[i] = item;
            i++;
        }

        //Create blob asset reference
        BlobAssetReference<BlobArray<T>> blobAsset = blobBuilder.CreateBlobAssetReference<BlobArray<T>>(Allocator.Persistent);
        blobBuilder.Dispose();
        return blobAsset;
    }

error ConstructBlobWithRefTypeViolation: You may not build a type S`1 with Construct as S`1.Value[] is a reference or pointer. Only non-reference types are allowed in Blobs.

auuuugh

quiet cliff
#

i guess it has to be known at compile time

#

what you could do is

#

instead of storing them as int/floats

#

store them as bytes

#

so BlobArray<byte>

sweet lava
#

store what as bytes

quiet cliff
#

if you know the type you are reading - you can cast the byte to an integer/float and read 4 elements at a time

#

much lower level but could probably work

sweet lava
#

Oh these are arrays of FixedString32 so they are already bytes

quiet cliff
#

idk how well fixedstring32 works with blobs

#

but if you were having trouble with fixedstring32 prior

#

i doubt it would work

sweet lava
#

i have no clue if thats what the issue was, the stack traces are hardly helpful

quiet cliff
#

could try again with fixedstring32

sweet lava
#

But dont i have to like, blob allocate strings too

#

BlobStrings

quiet cliff
#

what im thinking might work better is 2 blob arrays

#

one is the span of elements

#

the other is a span of characters/bytes (I forget if characters would work)

sweet lava
#

oh im not doing hashmaps anymore i just flattened them into arrays of strings with key | value

quiet cliff
#

oh

#

so it's like struct { FixedString32, FixedString32 }

sweet lava
#

no, key | value in a string. Less efficient to read but I just want to be done with this problem so I can move on

#

heres the coide so far

#

it still gives me errors. do I need to copy the array?...

quiet cliff
#

I'd imagine arr[i] = item is a copy

sweet lava
#

i thought so

quiet cliff
#

i want to say blobs probably don't work well with generics since it looks like Unity is throwing the error at compile time 🤔