Search Unity

[Answered] How, What, Why BlobAssetStore

Discussion in 'Entity Component System' started by Slarti-42, Feb 25, 2020.

  1. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    49
    [Update] Find explanation further down.

    Hi folks,

    I am scratching my head around the BlobAssetStore. Not much on Google. Been looking at the declaration and see that it puts things into a hashtable?

    Especially this line of code:

    Code (CSharp):
    1. GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);
    In order to understand, as I would like to, would somebody take a few minutes to explain this why the conversion settings are going into a hash, please?

    Thanks in advance.
    Slarti
     
    Last edited: Feb 29, 2020
    MintTree117 and TheGabelle like this.
  2. pal_trefall

    pal_trefall

    Joined:
    Feb 5, 2019
    Posts:
    78
    Not in front of the computer right now, but I usually go off their unit tests to see how they use blob stuff, because there's really not much/any documentation out there on it. There was also a talk that touched on it at Unite last year.
     
  3. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    398
    It doesn't really answer the question, but creating GameObjectConversionSettings from the constructor works for me and I don't have to set blobAssetStore parameter (which is the 3rd parameter in the constructor and it is null by default)
    Code (CSharp):
    1.         var conversionSettings = new GameObjectConversionSettings(World.DefaultGameObjectInjectionWorld,
    2.             GameObjectConversionUtility.ConversionFlags.AssignName);
     
  4. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    49
    So I continued to do some digging and found this
    So basically BLOB stands for Binary Large OBjects, where you store large binary object data.
    BLOBs are:
    Natively allocated.
    Immutable so they are job safe.
    Fast and trivial serialisation.
    Are blittable.
    You can copy a BLOB byte by byte not worrying about it, as it uses offsets and not memory addresses.

    It's not used for storing data that you want to change!

    You can make as well BLOB arrays and you can use them inside another BLOB.

    How to do a BLOB?
    First, declare a struct.
    After that, you declare a "builder" that you allocate temporarily.
    Code (CSharp):
    1. BlobBuilder builder = new BlobBuilder(Allocator.Temp);
    Then you design your structure, starting with at root with the data scheme you used in your struct.
    Code (CSharp):
    1. ref StructName structName = ref builder.ConstructRoot<StructName>();
    2. structName.xyz = 42;
    And last you set the BLOB asset Reference and allocate it persistently.
    Code (CSharp):
    1. BlobAssetReference<StructName> name = builder.CreateBlobAssetReference<StructName>(Allocator.Persistent);

    For more information and more about ECS find this very helpful Video:
     
    mikaelK, jdtec, varnon and 9 others like this.
  5. Slarti-42

    Slarti-42

    Joined:
    Jul 1, 2019
    Posts:
    49
    As well, today our @CodeMonkeyYT posted a nice video about them:

     
  6. peaj_metric

    peaj_metric

    Joined:
    Sep 15, 2014
    Posts:
    146
    Just to clear this up a bit.
    BlobAssetStore is not the same as a BlobAsset.
    The CodeMonkey video is about BlobAsset.
    BlobAssetStore is using a hashmap of BlobAssets internally to keep track of converted GameObjects.
    It seems to be mostly designed around Subscenes and the comment in the top of the files states that it is not thread safe.BlobAssets in contrast are safe to use across mutliple threads as they are immutable and readonly.
     
    BigRookGames likes this.