I thought there’s some kind of central BlobAsset database/storage somewhere that you can access. You create data once then access it anywhere. This doesn’t seem to be the case. My current understanding is that you build BlobAssetReference instances and it’s up to you how to store it. I made a basic test for this:
[TestFixture]
[Category("CommonEcs")]
public class BlobAssetTest : ECSTestsFixture {
private struct TestData {
public int value;
}
private struct TestComponent : IComponentData {
public BlobAssetReference<TestData> reference;
}
private const int TEST_DATA_VALUE = 111;
private class BlobAssetSystem : SystemBase {
private BlobAssetReference<TestData> reference;
protected override void OnCreate() {
base.OnCreate();
// Prepare the blob asset
BlobBuilder builder = new BlobBuilder(Allocator.TempJob);
ref TestData data = ref builder.ConstructRoot<TestData>();
data.value = TEST_DATA_VALUE;
this.reference = builder.CreateBlobAssetReference<TestData>(Allocator.Persistent);
builder.Dispose();
Entity entity = this.EntityManager.CreateEntity(typeof(TestComponent));
this.EntityManager.SetComponentData(entity, new TestComponent() {
reference = this.reference
});
}
protected override void OnDestroy() {
this.reference.Dispose();
}
protected override void OnUpdate() {
this.Entities.ForEach(delegate(in TestComponent component) {
Debug.Log($"value: {component.reference.Value.value}");
Assert.IsTrue(component.reference.Value.value == TEST_DATA_VALUE);
}).WithoutBurst().Run();
}
public void CreateNewEntity() {
Entity entity = this.EntityManager.CreateEntity(typeof(TestComponent));
this.EntityManager.SetComponentData(entity, new TestComponent() {
reference = this.reference
});
}
}
[Test]
public void BasicUsageTest() {
BlobAssetSystem system = this.World.GetOrCreateSystem<BlobAssetSystem>();
system.Update();
system.CreateNewEntity();
system.Update();
}
}
In this test, the BlobAssetReference is maintained as a member variable. What I’m imagining is that every time a new entity is created that requires this data, it has to use this member variable. To access this data from another system, I have to inject this system then access the member variable. I was hoping there was another way to access a specific BlobAssetReference without injecting a system or some other class where all BlobAssetReferences are stored. Or is there a method for what I want? Some like BlobAsset.GetReference().