pub struct DuplicationPlan<B, const N: usize>where
B: CloneBundle,{ /* private fields */ }Expand description
Owned snapshot of explicitly selected components for N distinct sources.
Created by World::plan_duplication. This holds no world borrow and never
rereads sources, even after edits/despawns. Each component’s Clone defines
whether its internal data stays shared (for example, an Rc<RefCell<_>>).
Dropping the plan discards the clones. Stack storage/work scales with N and
the selected bundle size; use small arrays for authoring. Clone may allocate.
The plan is not a whole-world, identity, hierarchy or reference-remapping clone.
Implementations§
Source§impl<B, const N: usize> DuplicationPlan<B, N>where
B: CloneBundle,
impl<B, const N: usize> DuplicationPlan<B, N>where
B: CloneBundle,
Sourcepub fn try_spawn(
self,
world: &mut World,
) -> Result<[(Entity, Entity); N], (SpawnError, DuplicationPlan<B, N>)>
pub fn try_spawn( self, world: &mut World, ) -> Result<[(Entity, Entity); N], (SpawnError, DuplicationPlan<B, N>)>
Spawns the captured bundles within the target’s prepared sparse budgets.
Returns exactly N (old, new) pairs in source order. Old identities are
informational: sources need not still exist. A different target world is
allowed; old/new handles then belong to their respective worlds and may
have equal bits. In the same world each new handle differs from every
source identity. Hosts explicitly remap any entity references afterward.
Uses World::try_spawn_batch without weakening its admission guarantees:
any reported error returns the entire plan for retry, without spawning,
dropping or recloning components. No ECS buffers/metadata grow on success;
preparation is the caller’s responsibility. A valid empty plan needs none.
User Clone/Drop and allocator panics/aborts are not caught or rolled back.
See World::plan_duplication for a complete actor-template recipe.