Entity reference in blob asset is broken without any warnings

When we build the blob asset of BlobAssetReference which contains entity reference in Baker, it simply serializes the entity’s index and version, so deserialized entity reference is completely broken(It is sometime randomly references some entity, or entity with invalid index or version).

I think entity reference in blob asset should be supported for prefab entity.
Also, invalid usage of entity reference in blob asset should emit warnings at baking.

1 Like

I know some will not agree with me.

Entity reference in a blob is supported but only if the blob is created at runtime.

BlobAssets are designed to store fast read only configuration data. I know nothing prevents you from writing to a Blob but it’s not what they were designed for.
Since the entity manipulated during the baking workflow are not the actual entity that end up in the runtime world, when you store a reference to an entity it needs to be remap after the baking. So you would need to write the new reference to the BlobAsset, which is supposed to be read only.

Could unity support entity remapping for blobs ? Most certainly.
Should they ? I’d like that.
Will they ? Probably not (but I’ll be happy to be proven wrong)

What will most likely happen is that at some point unity will come up with something similar to addressable for DOTS (they already started with ContentManagement) and at that point the recommendation will be to store the prefab “addressable” identifier rather than the actual Entity.

As for the warning message, if they can detect that, they can certainly prevent you from using Entity type in a blob. Which like I said is more likely to happen in my opinion.
And if they can’t they’ll keep getting confused user about why that work in IComponentData and IBufferElementData but not in blobs.

The easiest way to do this now is to patch the available blobs at runtime. Pretty hacky, but it gets the job done.

I hope this feature will be added at one point. It would be very useful because blobs are awesome when it comes to tight data layout and having the entity directly available would reduce one costly lookup into a hashmap as was suggested by WAYNGames above.