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

Remove insert_or_spawn function family #18148

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ElliottjPierce
Copy link
Contributor

Objective

Based on #18054, this PR builds on #18035 and #18147 to remove:

  • Commands::insert_or_spawn_batch
  • Entities::alloc_at_without_replacement
  • Entities::alloc_at
  • entity::AllocAtWithoutReplacement
  • World::insert_or_spawn_batch
  • World::insert_or_spawn_batch_with_caller

Testing

Just removing unused, deprecated code, so no new tests. Note that as of writing, #18035 is still under testing and review.

Future Work

Per this comment on #18054, there may be additional performance improvements possible to the entity allocator now that alloc_at no longer is supported. At a glance, I don't see anything obvious to improve, but it may be worth further investigation in the future.

Migration Guide

The following deprecated functions have been removed:

  • Commands::insert_or_spawn_batch
  • World::insert_or_spawn_batch
  • World::insert_or_spawn_batch_with_caller

These functions, when used incorrectly, can cause major performance problems and are generally viewed as anti-patterns and foot guns.

Instead of these functions consider doing one of the following:

Option A) Instead of despawing entities and re-spawning them at a particular id, insert the new Disabled component without despawning the entity, and use try_insert_batch or insert_batch and remove Disabled instead of re-spawning it.

Option B) Instead of giving special meaning to an entity id, simply use spawn_batch and ensure entity references are valid when despawning.

@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Mar 4, 2025
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change S-Blocked This cannot move forward until something else changes C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Blocked This cannot move forward until something else changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants