Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity.removeAllChildren() does not remove all children #2455

Closed
eonarheim opened this issue Aug 7, 2022 · 0 comments · Fixed by #2454
Closed

Entity.removeAllChildren() does not remove all children #2455

eonarheim opened this issue Aug 7, 2022 · 0 comments · Fixed by #2454

Comments

@eonarheim
Copy link
Member

Steps to Reproduce

Reported by @chrisk-7777 #2419 (comment)

https://codepen.io/chrisk7777/pen/gOeKOOy?editors=0010

Note how every second child is removed? Not all of them. This had me scratching my head, but after some digging, and I could be wrong, but I believe its because we're altering the array inside a loop:

https://github.com/excaliburjs/Excalibur/blob/main/src/engine/EntityComponentSystem/Entity.ts#L258

Expected Result

All children should be removed

Actual Result

Every other child is removed

Environment

  • browsers and versions: NA
  • operating system: NA
  • Excalibur versions: v0.27.0

Current Workaround

Manually iterate over the children and call removeChild individually

// Avoid modifying the array issue by walking backwards
for (let i = entity.children.length - 1; i >= 0; i--) {
  entity.removeChild(this.children[i]);
}
eonarheim added a commit that referenced this issue Aug 8, 2022
Closes #2455 
Closes #2456 

## Changes:

- Unparent children when `.kill()` is called
- Fix issue in `.removeAllChildren()` where the delete would modify the collection while iterating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant