BlobAssetReference vs Pointer

is it good design to store

struct Component : IComponentData {
   public BlobAssetReferece<T> Value;
}

as just

struct Component : IComponentData {
   public T* Value;
}

?
my thinking is that if the blob’s lifetime is controlled elsewhere, then there’s no point of boxing T. its just extra fluff since all a blob asset reference is it seems is a container around a pointer that essentially does this

struct BlobAssetReferece<T> {
   T *m_Field;
   public T Get() => *m_Field;
}

also i like wacky symbols like → * that make the source code look cool

Burst might get extra safety checks or optimizations around this. Plus, you don’t have to declare the component as unsafe.

I think intent is important. The blob structs are designed for a certain purpose.

If I see a random pointer on a component, I have no idea who or what is responsible for lifetime management and freeing the resource. Whereas if I see a BlobAssetReference I know how it should be handled.

There’s also NativeReference, which you won’t be attaching on a component, but provides a safe way to access unmanaged memory.

1 Like

+1 to what the others said. Your future self will thank you for not going to wacky (unsafe pointers) way :wink: