#Skyrbunny does not understand Blobs
1 messages · Page 1 of 1 (latest)
@quiet cliff here's my code: https://pastebin.com/pvFLwXX5
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Look at BloblificationTests
it shows how you can construct BlobAssetReferences
in FlattenBehaviours you're using a BlobBuilder
but you're not creating the BlobAssetReference
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?
Yea and it needs to live in a BlobAssetReference
hmm so I need to rewite... all of this...
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; //???
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
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;
}
okay cool. ints dont need to be blobassetreference right
yea sorry, you don't need them to be in a blob pointer or anything
they can remain as fields
ok cool
but it would mean that when you do a local copy, it would copy the values over
how do I make sure T is non nullable?
where T : unmanaged
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???
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
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
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>
store what as bytes
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
Oh these are arrays of FixedString32 so they are already bytes
idk how well fixedstring32 works with blobs
but if you were having trouble with fixedstring32 prior
i doubt it would work
i have no clue if thats what the issue was, the stack traces are hardly helpful
could try again with fixedstring32
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)
oh im not doing hashmaps anymore i just flattened them into arrays of strings with key | value
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
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
it still gives me errors. do I need to copy the array?...
I'd imagine arr[i] = item is a copy
i thought so
i want to say blobs probably don't work well with generics since it looks like Unity is throwing the error at compile time 🤔