I’m trying to learn DOTS from an online tutorial.
The intent is to take in GameObject prefab, turn it into entity prefab and then create any needed entities from that prefab. It ends with three same errors: “A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details.”, nothing else, double-clicking does nothing. Googling it shows that it happens to people in relation to analytics, but I have none, its turned off.
If executeOnStart is false, this error doesn’t happen. This script is attached to the GameObject:
public class PrefabSpawner : MonoBehaviour
{
public bool executeOnStart;
[SerializeField] GameObject gameObjectPrefab; // fails on anything, null, standard unity shape or a model.
Entity entityPrefab;
World defaultWorld;
EntityManager entityManager;
void Start()
{
defaultWorld = World.DefaultGameObjectInjectionWorld;
entityManager = defaultWorld.EntityManager;
if (executeOnStart) DoIt();
}
void DoIt()
{
EntityArchetype archetype = entityManager.CreateArchetype(
typeof(Translation),
typeof(Rotation),
typeof(RenderMesh),
typeof(RenderBounds),
typeof(LocalToWorld)
);
var settings = GameObjectConversionSettings.FromWorld(defaultWorld, new BlobAssetStore());
entityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(gameObjectPrefab, settings);
// Create 100 copies
for (var i = 0; i < 100; i++)
{
Entity myEntity = entityManager.Instantiate(entityPrefab);
entityManager.SetComponentData(myEntity, new Translation
{
Value = new float3(5, 10, 15)
});
}
}
}