Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Is this the valid pattern to convert a gameobject now?

Discussion in 'Entity Component System' started by sebas77, Mar 10, 2020.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    Now that the blob asset is not optional anymore I am not sure when to dispose it.

    var _blobStore = new BlobAssetStore();

    GameObjectConversionUtility.ConvertGameObjectHierarchy
    (item, GameObjectConversionSettings.FromWorld(physicsWorld, _blobStore));

    _blobStore.Dispose();

    Is disposing it immediately valid? If not what should suggest me that is not a valid pattern? If not am I supposed to hold on the blobasset and dispose it at the end of the application?
    If instead you reckon is a valid pattern, then there are some bugs I have to report.
     
    psuong likes this.
  2. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    272
    Im not sure how it is supposed to work, but I create an assetsore myself


    _assetStore = new BlobAssetStore();


    and dispose it in OnDestroy()
     
  3. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    yeah it seems that disposing it at the end of the execution is the safe way to use it, it's just strange that I didn't read it in the official documentation, but at this point I don't think I need an official answer.
     
  4. loicbaumann

    loicbaumann

    Unity Technologies

    Joined:
    Mar 21, 2019
    Posts:
    7
    If you can use the BlobAssetStore from the GameObjectConversionSystem or GameObjectConversionSettings, that's always the best thing to do.

    If you can't access it, what was suggested works just fine.
    In the case of ConvertGameObjectHiearchy you can keep the BlobAssetStore longer if you want to avoid the conversion system to reconvert identical BlobAsset.

    If you don't do it, they will be reconvert but the destination world will still use the optimal number of BlobAsset (because they also have a checksum internally for us to identify identical ones).

    TL;DR @sebas77 answer is correct.
     
    WAYNGames and DreamingImLatios like this.
  5. Lapsapnow

    Lapsapnow

    Joined:
    Jul 4, 2019
    Posts:
    51
    How exactly do you get the BlobAssetStore from the GameObjectConversionSystem?
     
  6. MaNaRz

    MaNaRz

    Joined:
    Aug 24, 2017
    Posts:
    117
    It's a property inside GameObjectConversionSystem.

    So from inside your Authoring Monobehaviour you just get it like this:
    Code (CSharp):
    1. public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    2.     {
    3.         var blobStore = conversionSystem.BlobAssetStore;
    4.     }
    5.      
     
  7. Lapsapnow

    Lapsapnow

    Joined:
    Jul 4, 2019
    Posts:
    51
    I'm using ConvertGameObjectHierarchy() within a Monobehaviour. I don't have access to conversionSystem. Explain? Or am I doing something wrong here?
     
  8. MaNaRz

    MaNaRz

    Joined:
    Aug 24, 2017
    Posts:
    117
    I'm not very familiar with ConvertGameObjectHierarchy() since it is not the recommended workflow for basic Conversion.
    I think ConvertGameObjectHierarchy() creates its own ConversionWorld each time you call it and disposes it right after that Hierarchy is Converted (and it's BlobAssetStore with it).

    So i guess you should hold on to your Store like loicbaumann suggested: