I am getting different errors after 730 entities with archetype exist in the world. 729 Entities works.
Here are some of the errors, whichever one shows up is seemingly random.
ArgumentException: All entities passed to EntityManager must exist. One of the entities has already been destroyed or was never created.
Assertion failure. Value was False
Expected: True
Assertion failure. Values are not equal.
Expected: 1 == 2
ArgumentException: Object reference not set to an instance of an object
ArgumentException: Invalid command buffer
public class SelectEntitySystem : JobComponentSystem
{
struct RemoveSelectionsJob : IJobForEachWithEntity<Selected>
{
[ReadOnly] public EntityCommandBuffer buffer;
public void Execute(Entity entity, int index, [ReadOnly] ref Selected selected)
{
buffer.RemoveComponent<Selected>(entity);
}
}
private EntityCommandBufferSystem bufferSystem;
protected override void OnCreateManager()
{
bufferSystem = World.Active.GetExistingSystem<EntityCommandBufferSystem>();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
JobHandle combinedInputDeps = inputDeps;
if (Input.GetMouseButtonDown(1))
{
// Remove all previous selections
EntityCommandBuffer unselectBuffer = bufferSystem.CreateCommandBuffer();
JobHandle unselect = new RemoveSelectionsJob() { buffer = unselectBuffer }.Schedule(this, inputDeps);
bufferSystem.AddJobHandleForProducer(unselect);
combinedInputDeps = JobHandle.CombineDependencies(inputDeps, unselect);
}
return combinedInputDeps;
}
}