Remove insert_or_spawn
function family
#18148
Open
+17
−393
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 usetry_insert_batch
orinsert_batch
and removeDisabled
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.