Skip to content

Commit

Permalink
feat(#44): ECS.removeEntities(world, query)
Browse files Browse the repository at this point in the history
- updating README with samples of removeEntities
  • Loading branch information
chriscoderdr committed Nov 10, 2024
1 parent 9848069 commit 9594286
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ ECS.getEntities(world, [ 'test_component' ]).length // because we are not defer
```



### removeEntities Example

You can use `ECS.removeEntities` to remove all entities with a specified component. For example, if you have entities with an `ephemeral` component and want to delete them from the world, you can do this:

```javascript
// remove all entities that have an 'ephemeral' component
ECS.removeEntities(world, ['ephemeral']);
```

The `removeEntities` function also supports the **not filter**, which allows you to specify components that should **not** be present on the entities you want to remove. For example, to remove entities that have a `transform` component but lack a `health` component, you can use the following code:

```javascript
// remove all entities that have a 'transform' component and lack a 'health' component
ECS.removeEntities(world, ['transform', '!health']);
```

This functionality can be useful for cleaning up entities that meet specific component criteria in your world.


### get entity by unique id

ECS will generate a unique integer id for every entity created in a world:
Expand Down

0 comments on commit 9594286

Please sign in to comment.