Search Unity

Cant Convert GameObject to Entity in 0.3 version

Discussion in 'Entity Component System' started by Opeth001, Dec 4, 2019.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Hello Everyone,

    I upgraded my project from entities 0.1 to 0.3.


    my MonoBehaviour code is converting a prefab and instantiating it's entities x times.(got it from ECSSamples)
    Code (CSharp):
    1.  
    2. players = new NativeArray<Entity>(pSkins.Length, Allocator.Persistent);
    3. // Create entity prefab from the Player GameObject Prefab Architype once
    4. var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null); // Error Here
    5. var prefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(clientPlayerPrefabArchitype, settings);
    6. var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    7.  
    8. // Efficiently instantiate a bunch of entities from the already converted entity prefab
    9. entityManager.Instantiate(prefab, players);
    10.  
    11.  

    The Error:
    Code (CSharp):
    1. ArgumentNullException: A valid BlobAssetStore must be passed to construct a BlobAssetComputationContext
    2. Parameter name: blobAssetStore
    3. Unity.Entities.BlobAssetComputationContext`2[TS,TB]..ctor (Unity.Entities.BlobAssetStore blobAssetStore, System.Int32 initialCapacity, Unity.Collections.Allocator allocator) (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities.Hybrid/GameObjectConversion/BlobAssetComputationContext.cs:31)
    4. Unity.Physics.Authoring.BeginColliderConversionSystem.OnUpdate () (at Library/PackageCache/com.unity.physics@0.2.5-preview/Unity.Physics.Hybrid/Conversion/BeginColliderConversionSystem.cs:14)
    5. Unity.Entities.ComponentSystem.InternalUpdate () (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystem.cs:102)
    6. Unity.Entities.ComponentSystemBase.Update () (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystemBase.cs:301)
    7. Unity.Entities.ComponentSystemGroup.OnUpdate () (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystemGroup.cs:109)
    8. UnityEngine.DebugLogHandler:LogException(Exception, Object)
    9. Unity.Entities.Conversion.JournalingUnityLogger:LogException(Exception, Object) (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities.Hybrid/GameObjectConversion/JournalingUnityLogger.cs:50)
    10. UnityEngine.Debug:LogException(Exception)
    11. Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/Stubs/Unity/Debug.cs:19)
    12. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystemGroup.cs:113)
    13. Unity.Entities.ComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystem.cs:102)
    14. Unity.Entities.ComponentSystemBase:Update() (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystemBase.cs:301)
    15. Unity.Entities.GameObjectConversionUtility:Convert(World) (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities.Hybrid/GameObjectConversion/GameObjectConversionUtility.cs:147)
    16. Unity.Entities.GameObjectConversionUtility:ConvertGameObjectHierarchy(GameObject, GameObjectConversionSettings) (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities.Hybrid/GameObjectConversion/GameObjectConversionUtility.cs:229)
     
  2. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    it's working now by changing this part:
    Code (CSharp):
    1.  
    2. var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
    3.  
    4. to
    5.  
    6. var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, new BlobAssetStore());
     
  3. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    im using Entities 0.4 and this workaround dont works correctly for some android devices,(the player goes under the ground)
     
    MahdiNfa and aVaKus like this.
  4. james7132

    james7132

    Joined:
    Mar 6, 2015
    Posts:
    166
    Was this ever fixed? I am getting the same issue now as well.

    Edit: Nevermind did not read all of the posts in the thread.
     
    Last edited: Aug 11, 2020
  5. Rob-A

    Rob-A

    Joined:
    Aug 7, 2012
    Posts:
    33
    Can confirm this happening in 0.14.0-preview.18 still.

    this solution seems to work for me.
     
  6. TWolfram

    TWolfram

    Joined:
    Aug 6, 2017
    Posts:
    75
    For me this results in a memory leak, using Entities 0.17.0-preview.41
     
  7. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    967
    The BlobAssetStore has to be disposed afterwards.
     
    jmcusack and Opeth001 like this.
  8. voidraizer

    voidraizer

    Joined:
    Dec 20, 2013
    Posts:
    6
    I also get a memory leak so I tried to dispose afterward and as soon as the prefab is spawned, I get lots of errors
    upload_2021-3-7_14-12-27.png

    upload_2021-3-7_14-11-36.png
     
  9. TWolfram

    TWolfram

    Joined:
    Aug 6, 2017
    Posts:
    75
    Exactly, trying to fix the memory leak only results in more errors. Would love to hear how we're supposed to properly dispose a blobassetstore.
     
  10. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    967
    I have pretty much the same code as @voidraizer, only that I don't use physics with it. From what I know, Physics stores data in the BlobAssetStore so it can't be just disposed in that case.

    What's holding you back from putting a "Convert to Entity" component on your prefabs?
     
  11. Shudrum

    Shudrum

    Joined:
    Apr 3, 2011
    Posts:
    63
    Sorry, just seen that because I had the same issue and fixed it. So necro time!

    I don't know your context, but on my test project, my spawner is a Monobehavior. To fix this issue, and avoid the BlobAssetStore to be garbage collected, I had to put it as a member and dispose it on destroy:

    Code (CSharp):
    1.  
    2. public class Spawner : MonoBehaviour
    3. {
    4.   public GameObject unit;
    5.  
    6.   private EntityManager _manager;
    7.   private Entity _enemyEntityPrefab;
    8.   private BlobAssetStore _blobAssetStore;
    9.  
    10.   private void Start() {
    11.     _blobAssetStore = new BlobAssetStore();
    12.     _manager = World.DefaultGameObjectInjectionWorld.EntityManager;
    13.     _enemyEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(
    14.       unit,
    15.       GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, _blobAssetStore)
    16.     );
    17.   }
    18.  
    19.   private void OnDestroy() {
    20.     _blobAssetStore.Dispose();
    21.   }
    22. }
    23.  
     
  12. julianwitte

    julianwitte

    Joined:
    Oct 3, 2012
    Posts:
    12
    Easier then managing your own BlobAssetStore would be using the conversion system BlobAsset;


    Code (CSharp):
    1. var world = World.DefaultGameObjectInjectionWorld;
    2.         var conversionSystem = world.GetExistingSystem<GameObjectConversionSystem>();
    3.  
    4.         var prefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(unitPrefab,
    5.             GameObjectConversionSettings.FromWorld(world, conversionSystem.BlobAssetStore));
    If you are using IConvertGameObjectToEntity then it is even easier, since conversionSystem comes for free in the Convert method.
     
  13. DevViktoria

    DevViktoria

    Joined:
    Apr 6, 2021
    Posts:
    94
    Actually in Entities 0.50 the ConvertToEntitySystem should be used like so:
    Code (CSharp):
    1. ConvertToEntitySystem convertToEntitySystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem<ConvertToEntitySystem>();
    2.         GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, convertToEntitySystem.BlobAssetStore);
    (The GameObjectConversionSystem was null when I tried to use it ....)
     
    mk1987 and gnere4 like this.
  14. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    This thread was created in 2019!
    OP was discussing early version of entities.

    Please checkout the dates before posting.
     
    Anthiese likes this.
  15. DevViktoria

    DevViktoria

    Joined:
    Apr 6, 2021
    Posts:
    94
    The reason I had posted here was because I ran into the same problem with ECS 0.50 and this thread came out in search. And I thought it would be great if the solution for the 0.50 could be found here. Sorry if I had made a mistake.
     
    dabmantrips_unity likes this.
  16. gladieweb

    gladieweb

    Joined:
    Sep 7, 2012
    Posts:
    8
    I still have this error and cannot fix it