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);
var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, null);
to
var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, new 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.
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.