Cant Convert GameObject to Entity in 0.3 version

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)

players = new NativeArray<Entity>(pSkins.Length, Allocator.Persistent); 
// Create entity prefab from the Player GameObject Prefab Architype once
var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null); // Error Here
var prefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(clientPlayerPrefabArchitype, settings); 
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

// Efficiently instantiate a bunch of entities from the already converted entity prefab
entityManager.Instantiate(prefab, players);

The Error:

ArgumentNullException: A valid BlobAssetStore must be passed to construct a BlobAssetComputationContext
Parameter name: blobAssetStore
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)
Unity.Physics.Authoring.BeginColliderConversionSystem.OnUpdate () (at Library/PackageCache/com.unity.physics@0.2.5-preview/Unity.Physics.Hybrid/Conversion/BeginColliderConversionSystem.cs:14)
Unity.Entities.ComponentSystem.InternalUpdate () (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystem.cs:102)
Unity.Entities.ComponentSystemBase.Update () (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystemBase.cs:301)
Unity.Entities.ComponentSystemGroup.OnUpdate () (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystemGroup.cs:109)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
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)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystemGroup.cs:113)
Unity.Entities.ComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystem.cs:102)
Unity.Entities.ComponentSystemBase:Update() (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities/ComponentSystemBase.cs:301)
Unity.Entities.GameObjectConversionUtility:Convert(World) (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities.Hybrid/GameObjectConversion/GameObjectConversionUtility.cs:147)
Unity.Entities.GameObjectConversionUtility:ConvertGameObjectHierarchy(GameObject, GameObjectConversionSettings) (at Library/PackageCache/com.unity.entities@0.3.0-preview.4/Unity.Entities.Hybrid/GameObjectConversion/GameObjectConversionUtility.cs:229)
5 Likes

it's working now by changing this part:

var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);

to

var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, new BlobAssetStore());
17 Likes

im using Entities 0.4 and this workaround dont works correctly for some android devices,(the player goes under the ground)

2 Likes

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.

Can confirm this happening in 0.14.0-preview.18 still.

this solution seems to work for me.

For me this results in a memory leak, using Entities 0.17.0-preview.41

The BlobAssetStore has to be disposed afterwards.

2 Likes

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
6910637--809900--upload_2021-3-7_14-12-27.png

6910637--809897--upload_2021-3-7_14-11-36.png

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.

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?

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:

public class Spawner : MonoBehaviour
{
  public GameObject unit;

  private EntityManager _manager;
  private Entity _enemyEntityPrefab;
  private BlobAssetStore _blobAssetStore;

  private void Start() {
    _blobAssetStore = new BlobAssetStore();
    _manager = World.DefaultGameObjectInjectionWorld.EntityManager;
    _enemyEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(
      unit,
      GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, _blobAssetStore)
    );
  }

  private void OnDestroy() {
    _blobAssetStore.Dispose();
  }
}

Easier then managing your own BlobAssetStore would be using the conversion system BlobAsset;

var world = World.DefaultGameObjectInjectionWorld;
        var conversionSystem = world.GetExistingSystem<GameObjectConversionSystem>();

        var prefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(unitPrefab,
            GameObjectConversionSettings.FromWorld(world, conversionSystem.BlobAssetStore));

If you are using IConvertGameObjectToEntity then it is even easier, since conversionSystem comes for free in the Convert method.

3 Likes

Actually in Entities 0.50 the ConvertToEntitySystem should be used like so:

ConvertToEntitySystem convertToEntitySystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem<ConvertToEntitySystem>();
        GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, convertToEntitySystem.BlobAssetStore);

(The GameObjectConversionSystem was null when I tried to use it …)

2 Likes

This thread was created in 2019!
OP was discussing early version of entities.

Please checkout the dates before posting.

1 Like

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.

1 Like

I still have this error and cannot fix it