Exposing ScriptableObject to DOTS

I have some data as ScriptableObject and want to expose it to DOTS. I intend to do it through BlobAssetReference.

I can create BlobAssetReference in IConvertGameObjectToEntity.Convert.
To prevent duplication I could use conversionSystem.BlobAssetStore and use ScriptableObject GUID as Hash

Is this correct approach?
Will this work with LiveLink? (should I use BlobAssetComputationContext?)

  • I mean sending ScriptableObject modifications through LiveLink
  • I guess not, because it’s not even working for Prefabs?

When I create BlobAssetReference and assign it to component, who will Dispose it?

public class ObjectWithDefinition : MonoBehaviour, IConvertGameObjectToEntity
{
    public SimpleDefinition Definition;
    public int Value;

    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var hash = new Unity.Entities.Hash128(UnityEditor.AssetDatabase.AssetPathToGUID(UnityEditor.AssetDatabase.GetAssetPath(Definition)));

        if (!conversionSystem.BlobAssetStore.TryGet(hash, out BlobAssetReference<SimpleDefinitionData> blob))
        {
            SimpleDefinitionData def;
            def.Name = new Unity.Collections.NativeString32(Definition.Name);
            def.Value = Definition.SomeValue;
            blob = BlobAssetReference<SimpleDefinitionData>.Create(def);
            conversionSystem.BlobAssetStore.TryAdd(hash, blob);
        }

        ObjectWithDefinitionData data;
        data.Definition = blob;
        data.Value = Value;
        dstManager.SetComponentData(entity, data);
    }
}

I have made a utility framework of my own you can use directly or as a point of reference:

2 Likes

Thanks, I see it works in similar fashion. Do you have an idea what destroys created BlobAssetReferences?
Also what creates ScriptableObjectConversionSystem or do I have to create somehow?