bevyengine/bevy · error
too many entities
Error message
too many entities
What it means
Cold-path panic in FreshAllocator::on_overflow: the atomic next_entity_index reached MAX_ENTITIES (u32::MAX), so the allocator can never hand out another fresh index. This is an aggregate capacity exhaustion across all frees/allocations in this allocator, not a per-frame spike; the helper exists to keep the panic message and branch in one place.
Source
Thrown at crates/bevy_ecs/src/entity/remote_allocator.rs:770
}
impl FreshAllocator {
/// This exists because it may possibly change depending on platform.
/// Ex: We may want this to be smaller on 32 bit platforms at some point.
const MAX_ENTITIES: u32 = u32::MAX;
/// The total number of indices given out.
#[inline]
fn total_entity_indices(&self) -> u32 {
self.next_entity_index.load(Ordering::Relaxed)
}
/// This just panics.
/// It is included to help with branch prediction, and put the panic message in one spot.
#[cold]
#[inline]
fn on_overflow() -> ! {
panic!("too many entities")
}
/// Allocates a fresh [`EntityIndex`].
/// This row has never been given out before.
#[inline]
fn alloc(&self) -> Entity {
let index = self.next_entity_index.fetch_add(1, Ordering::Relaxed);
if index == Self::MAX_ENTITIES {
Self::on_overflow();
}
// SAFETY: We just checked that this was not max and we only added 1, so we can't have missed it.
Entity::from_index(unsafe { EntityIndex::new(NonMaxU32::new_unchecked(index)) })
}
/// Allocates `count` [`EntityIndex`]s.
/// These rows will be fresh.
/// They have never been given out before.
fn alloc_many(&self, count: u32) -> AllocUniqueEntityIndexIterator {View on GitHub (pinned to 396ca72708)
Solutions
- Free and recycle entity indices (despawn) instead of allocating indefinitely
- Reduce entity churn: reuse pools for frequently spawned/despawned entities
- For truly enormous workloads, shard work across multiple Worlds/allocators
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_ecs/src/entity/remote_allocator.rs:770 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/d50e313e417584d2.
Report an issue: GitHub.