Save/Correct way to handle BlobAssetReference

Wondering if someone could please help me out. Basically I want to create BlobAssetReference from different GO using IConvertGameObjectToEntity and then add them all to a single entity in a GameObjectConversionSystem.

How do i create a BlobAssetReference safely outside using{}, access it in a GameObjectConversionSystem and dispose.

public class GameObj_A_Authoring : MonoBehaviour, IConvertGameObjectToEntity
{
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        BlobAssetReference<DataA>  basDataA = BuildBlobA();
    }

}
public class GameObj_B_Authoring : MonoBehaviour, IConvertGameObjectToEntity
{
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        BlobAssetReference<DataB>  basDataB = BuildBlobB();
    }

}
public class MyConversionSystem : GameObjectConversionSystem
{
  //.. Safely create and add this to an entity
  var comp = new AllBlobsComponent
  {
      // add BlobAssetReference<DataA>
      // add BlobAssetReference<DataB>
  };
 
}

Can any one please share a simple example to safely do this. Thank you heaps in advance

I don’t know how to combine existing BlobAssets, but you might be able to restructure your code to take a BlobBuilder.

struct ComponentA { public int x; }
struct ComponentB { public BlobArray<int> y; }
struct AllBlobs { public ComponentA a; public ComponentB b; }

class ComponentA_Authoring {
    public void SetBlobData(ref ComponentA obj, ref BlobBuilder bb) {
        obj.x = 15; } }

class ComponentB_Authoring {
    public void SetBlobData(ref ComponentB obj, ref BlobBuilder bb) {
        BlobBuilderArray<int> arr = bb.Allocate(ref obj.y, 3);
        arr[0] = 10;
        arr[1] = -60;
        arr[2] = 88; } }

class MyConversionSystem {
    public BlobAssetReference<AllBlobs> Convert() {
        BlobBuilder bb = new BlobBuilder(Allocator.Temp);
        ref AllBlobs root = ref bb.ConstructRoot<AllBlobs>();
        myComponentA.SetBlobData(ref root.a, ref bb);
        myComponentB.SetBlobData(ref root.b, ref bb);
        return bb.CreateBlobAssetReference<AllBlobs>(Allocator.Persistent); } }

For a bigger example: https://gitlab.com/burningmime/easybuilding/-/blob/master/Packages/building/src/Building.cs#L633

1 Like

Thank you let me try this out

Look at physics conversion, it’s pretty much what it does.

For the life of me i cant find it, Iv only downloaded the physics package for the first time today so pretty lost, I found Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics.Hybrid/Conversion but cant find the example you are referring too.

Oh sorry, I kind of miss read your original post.

I thought you were trying to apply the same blob asset reference to multiple entities, but you want to create references on multiple entities then group them after on a single entity.

Could you just make your final conversion system run after the conversion is done and filter on the destination world?

“Could you just make your final conversion system run after the conversion is done and filter on the destination world”

not sure follow , so I just create a BlobAssetReference in each conversion, store it in the destination world on the primary entity and then in the conversion system create a new entity and add each BlobAssetReference so that I have a single entity with a component container a BlobAssetReference to each blob

Seems like you follow fine!

Fantastic , thank you