I am using Entities v0.8
I am trying to build a Spawner, and this is the system
using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
public class ChunkSpawnerSystem : SystemBase
{
protected override void OnUpdate()
{
Entities.ForEach((ref ChunkSpawnerComponent spawner) =>
{
if (!spawner.needsRender) return;
EntityArchetype chunkArchetype = EntityManager.CreateArchetype(new ComponentType[] { typeof(Translation) });
for (int id = 0; id < spawner.size; id++)
{
Debug.Log("Rendering chunk " + id);
Entity entity = EntityManager.CreateEntity(chunkArchetype);
EntityManager.SetName(entity, "Chunk " + id);
}
spawner.needsRender = false;
}).Schedule();
}
}
But I get the following error
ChunkSpawnerSystem.cs(9,9): error DC0002: Entities.ForEach Lambda expression invokes 'get_EntityManager' on a ChunkSpawnerSystem which is a reference type. This is only allowed with .WithoutBurst() and .Run().
Apparently I cannot seem to be able to use EntityManager inside the lambda function. Why is this?