diff --git a/crates/bevy_ecs/src/world/archetype_invariants.rs b/crates/bevy_ecs/src/world/archetype_invariants.rs index 0832b908425fb2..5d6336a263325c 100644 --- a/crates/bevy_ecs/src/world/archetype_invariants.rs +++ b/crates/bevy_ecs/src/world/archetype_invariants.rs @@ -402,6 +402,27 @@ mod tests { world.add_archetype_invariant(ArchetypeInvariant::<(A, B, C)>::atomic()); } + #[test] + fn on_insert_untyped_happy() { + let mut world = World::new(); + + world.spawn().insert_bundle((A, B, C)); + let archetype_invariant = + ArchetypeInvariant::<(A, B, C)>::atomic().into_untyped(&mut world); + world.add_untyped_archetype_invariant(archetype_invariant); + } + + #[test] + #[should_panic] + fn on_insert_untyped_sad() { + let mut world = World::new(); + + world.spawn().insert_bundle((A, B)); + let archetype_invariant = + ArchetypeInvariant::<(A, B, C)>::atomic().into_untyped(&mut world); + world.add_untyped_archetype_invariant(archetype_invariant); + } + #[test] fn forbids_happy() { let mut world = World::new(); diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 12aa56fa9f664f..00e2ee519e3d16 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -679,6 +679,11 @@ impl World { &mut self, archetype_invariant: UntypedArchetypeInvariant, ) { + for archetype in &self.archetypes.archetypes { + let components = archetype.components.indices(); + archetype_invariant.test_archetype(components); + } + self.archetype_invariants.add(archetype_invariant); }