Skip to content

removing components while iterating #15

@sh-dave

Description

@sh-dave

What's the intended way of doing that?

var objs = new View<A, B>();
... initialize objs with something...

for (e in objs.entities) {
   objs.manager.components.remove(e, A);
}

This won't work for all entities, as entities without A will be overwritten immediately.

  • say we have these entities [0, 1, 2, 3]; Length 4 in objs, that all match
  • the first iteration will remove A from 0;
  • objs.entities will now contain [3, 1, 2, 3] / Length 3;
  • next iteration, remove A from 1
  • objs.entities will now container[3, 2, 2, 3] / Length 2;
  • iteration will stop now

A workaround i found is using View.entities.entities
This will properly remove A from every entity, but it seems hard to remember.

for (e in objs.entities.entities) {
   objs.manager.components.remove(e, A);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions