Is it normal for coimponents not being removed on the entities?
JoaoVictorVP opened this issue · 2 comments
Quite literally, this code:
var query = new QueryDescription().WithAll<Position, MoveTo>();
world.Query(query, (ref Entity entity, ref Position pos, ref MoveTo moveTo) =>
{
var distance = Vector2.Distance(pos.Pos, moveTo.To);
if (distance > moveTo.StopDistance)
{
var direction = Vector2.Normalize(moveTo.To - pos.Pos);
pos.Pos += direction * moveTo.Speed * Time.DeltaTime;
}
else
world.Remove<MoveTo>(entity);
});
Will not remove the components from the entities, it will get into the world.Remove line and run it, and then nothing will change. And then in the next iteration it will run again.
And when I'm testing with more than 50 entities simultaneously, I get an "index out of bounds" error.
Ah, and I tried it with the CommandBuffer as well, it results in the same out of bounds error and the components are also not removed at all
Nevermind, it was a silly mistake. After visiting the source code I found the problem to be the (ref Entity entity) part, there was not an overload with ref Entity and thus it interpreted Entity as a component when querying, what is strange is that the queries were still running but the error now makes sense.