Path: blob/main/crates/bevy_ecs/src/reflect/entity_commands.rs
9408 views
use crate::{1prelude::Mut,2reflect::{AppTypeRegistry, ReflectBundle, ReflectComponent},3resource::Resource,4system::EntityCommands,5world::EntityWorldMut,6};7use alloc::{borrow::Cow, boxed::Box};8use bevy_reflect::{PartialReflect, Reflect, TypeRegistry};910/// An extension trait for [`EntityCommands`] for reflection related functions11pub trait ReflectCommandExt {12/// Adds the given boxed reflect component or bundle to the entity using the reflection data in13/// [`AppTypeRegistry`].14///15/// This will overwrite any previous component(s) of the same type.16///17/// # Panics18///19/// - If the entity doesn't exist.20/// - If [`AppTypeRegistry`] does not have the reflection data for the given21/// [`Component`](crate::component::Component) or [`Bundle`](crate::bundle::Bundle).22/// - If the component or bundle data is invalid. See [`PartialReflect::apply`] for further details.23/// - If [`AppTypeRegistry`] is not present in the [`World`](crate::world::World).24///25/// # Note26///27/// Prefer to use the typed [`EntityCommands::insert`] if possible. Adding a reflected component28/// is much slower.29///30/// # Example31///32/// ```33/// // Note that you need to register the component type in the AppTypeRegistry prior to using34/// // reflection. You can use the helpers on the App with `app.register_type::<ComponentA>()`35/// // or write to the TypeRegistry directly to register all your components36///37/// # use bevy_ecs::prelude::*;38/// # use bevy_ecs::reflect::{ReflectCommandExt, ReflectBundle};39/// # use bevy_reflect::{FromReflect, FromType, Reflect, TypeRegistry};40/// // A resource that can hold any component that implements reflect as a boxed reflect component41/// #[derive(Resource)]42/// struct Prefab {43/// data: Box<dyn Reflect>,44/// }45/// #[derive(Component, Reflect, Default)]46/// #[reflect(Component)]47/// struct ComponentA(u32);48///49/// #[derive(Component, Reflect, Default)]50/// #[reflect(Component)]51/// struct ComponentB(String);52///53/// #[derive(Bundle, Reflect, Default)]54/// #[reflect(Bundle)]55/// struct BundleA {56/// a: ComponentA,57/// b: ComponentB,58/// }59///60/// fn insert_reflect_component(61/// mut commands: Commands,62/// mut prefab: ResMut<Prefab>63/// ) {64/// // Create a set of new boxed reflect components to use65/// let boxed_reflect_component_a: Box<dyn Reflect> = Box::new(ComponentA(916));66/// let boxed_reflect_component_b: Box<dyn Reflect> = Box::new(ComponentB("NineSixteen".to_string()));67/// let boxed_reflect_bundle_a: Box<dyn Reflect> = Box::new(BundleA {68/// a: ComponentA(24),69/// b: ComponentB("Twenty-Four".to_string()),70/// });71///72/// // You can overwrite the component in the resource with either ComponentA or ComponentB73/// prefab.data = boxed_reflect_component_a;74/// prefab.data = boxed_reflect_component_b;75///76/// // Or even with BundleA77/// prefab.data = boxed_reflect_bundle_a;78///79/// // No matter which component or bundle is in the resource and without knowing the exact type, you can80/// // use the insert_reflect entity command to insert that component/bundle into an entity.81/// commands82/// .spawn_empty()83/// .insert_reflect(prefab.data.reflect_clone().unwrap().into_partial_reflect());84/// }85/// ```86fn insert_reflect(&mut self, component: Box<dyn PartialReflect>) -> &mut Self;8788/// Same as [`insert_reflect`](ReflectCommandExt::insert_reflect), but using the `T` resource as type registry instead of89/// `AppTypeRegistry`.90///91/// # Panics92///93/// - If the given [`Resource`] is not present in the [`World`](crate::world::World).94///95/// # Note96///97/// - The given [`Resource`] is removed from the [`World`](crate::world::World) before the command is applied.98fn insert_reflect_with_registry<T: Resource + AsRef<TypeRegistry>>(99&mut self,100component: Box<dyn PartialReflect>,101) -> &mut Self;102103/// Removes from the entity the component or bundle with the given type path registered in [`AppTypeRegistry`].104///105/// If the type is a bundle, it will remove any components in that bundle regardless if the entity106/// contains all the components.107///108/// Does nothing if the type is a component and the entity does not have a component of the same type,109/// if the type is a bundle and the entity does not contain any of the components in the bundle,110/// if [`AppTypeRegistry`] does not contain the reflection data for the given component,111/// or if the entity does not exist.112///113/// # Note114///115/// Prefer to use the typed [`EntityCommands::remove`] if possible. Removing a reflected component116/// is much slower.117///118/// # Example119///120/// ```121/// // Note that you need to register the component/bundle type in the AppTypeRegistry prior to using122/// // reflection. You can use the helpers on the App with `app.register_type::<ComponentA>()`123/// // or write to the TypeRegistry directly to register all your components and bundles124///125/// # use bevy_ecs::prelude::*;126/// # use bevy_ecs::reflect::{ReflectCommandExt, ReflectBundle};127/// # use bevy_reflect::{FromReflect, FromType, Reflect, TypeRegistry};128///129/// // A resource that can hold any component or bundle that implements reflect as a boxed reflect130/// #[derive(Resource)]131/// struct Prefab{132/// entity: Entity,133/// data: Box<dyn Reflect>,134/// }135/// #[derive(Component, Reflect, Default)]136/// #[reflect(Component)]137/// struct ComponentA(u32);138/// #[derive(Component, Reflect, Default)]139/// #[reflect(Component)]140/// struct ComponentB(String);141/// #[derive(Bundle, Reflect, Default)]142/// #[reflect(Bundle)]143/// struct BundleA {144/// a: ComponentA,145/// b: ComponentB,146/// }147///148/// fn remove_reflect_component(149/// mut commands: Commands,150/// prefab: Res<Prefab>151/// ) {152/// // Prefab can hold any boxed reflect component or bundle. In this case either153/// // ComponentA, ComponentB, or BundleA. No matter which component or bundle is in the resource though,154/// // we can attempt to remove any component (or set of components in the case of a bundle)155/// // of that same type from an entity.156/// commands.entity(prefab.entity)157/// .remove_reflect(prefab.data.reflect_type_path().to_owned());158/// }159/// ```160fn remove_reflect(&mut self, component_type_path: impl Into<Cow<'static, str>>) -> &mut Self;161/// Same as [`remove_reflect`](ReflectCommandExt::remove_reflect), but using the `T` resource as type registry instead of162/// `AppTypeRegistry`.163fn remove_reflect_with_registry<T: Resource + AsRef<TypeRegistry>>(164&mut self,165component_type_path: impl Into<Cow<'static, str>>,166) -> &mut Self;167}168169impl ReflectCommandExt for EntityCommands<'_> {170fn insert_reflect(&mut self, component: Box<dyn PartialReflect>) -> &mut Self {171self.queue(move |mut entity: EntityWorldMut| {172entity.insert_reflect(component);173})174}175176fn insert_reflect_with_registry<T: Resource + AsRef<TypeRegistry>>(177&mut self,178component: Box<dyn PartialReflect>,179) -> &mut Self {180self.queue(move |mut entity: EntityWorldMut| {181entity.insert_reflect_with_registry::<T>(component);182})183}184185fn remove_reflect(&mut self, component_type_path: impl Into<Cow<'static, str>>) -> &mut Self {186let component_type_path: Cow<'static, str> = component_type_path.into();187self.queue(move |mut entity: EntityWorldMut| {188entity.remove_reflect(component_type_path);189})190}191192fn remove_reflect_with_registry<T: Resource + AsRef<TypeRegistry>>(193&mut self,194component_type_path: impl Into<Cow<'static, str>>,195) -> &mut Self {196let component_type_path: Cow<'static, str> = component_type_path.into();197self.queue(move |mut entity: EntityWorldMut| {198entity.remove_reflect_with_registry::<T>(component_type_path);199})200}201}202203impl<'w> EntityWorldMut<'w> {204/// Adds the given boxed reflect component or bundle to the entity using the reflection data in205/// [`AppTypeRegistry`].206///207/// This will overwrite any previous component(s) of the same type.208///209/// # Panics210///211/// - If the entity has been despawned while this `EntityWorldMut` is still alive.212/// - If [`AppTypeRegistry`] does not have the reflection data for the given213/// [`Component`](crate::component::Component) or [`Bundle`](crate::bundle::Bundle).214/// - If the component or bundle data is invalid. See [`PartialReflect::apply`] for further details.215/// - If [`AppTypeRegistry`] is not present in the [`World`](crate::world::World).216///217/// # Note218///219/// Prefer to use the typed [`EntityWorldMut::insert`] if possible. Adding a reflected component220/// is much slower.221pub fn insert_reflect(&mut self, component: Box<dyn PartialReflect>) -> &mut Self {222self.assert_not_despawned();223self.resource_scope(|entity, registry: Mut<AppTypeRegistry>| {224let type_registry = ®istry.as_ref().read();225insert_reflect_with_registry_ref(entity, type_registry, component);226});227self228}229230/// Same as [`insert_reflect`](EntityWorldMut::insert_reflect), but using231/// the `T` resource as type registry instead of [`AppTypeRegistry`].232///233/// This will overwrite any previous component(s) of the same type.234///235/// # Panics236///237/// - If the entity has been despawned while this `EntityWorldMut` is still alive.238/// - If the given [`Resource`] does not have the reflection data for the given239/// [`Component`](crate::component::Component) or [`Bundle`](crate::bundle::Bundle).240/// - If the component or bundle data is invalid. See [`PartialReflect::apply`] for further details.241/// - If the given [`Resource`] is not present in the [`World`](crate::world::World).242pub fn insert_reflect_with_registry<T: Resource + AsRef<TypeRegistry>>(243&mut self,244component: Box<dyn PartialReflect>,245) -> &mut Self {246self.assert_not_despawned();247self.resource_scope(|entity, registry: Mut<T>| {248let type_registry = registry.as_ref().as_ref();249insert_reflect_with_registry_ref(entity, type_registry, component);250});251self252}253254/// Removes from the entity the component or bundle with the given type path registered in [`AppTypeRegistry`].255///256/// If the type is a bundle, it will remove any components in that bundle regardless if the entity257/// contains all the components.258///259/// Does nothing if the type is a component and the entity does not have a component of the same type,260/// if the type is a bundle and the entity does not contain any of the components in the bundle,261/// or if [`AppTypeRegistry`] does not contain the reflection data for the given component.262///263/// # Panics264///265/// - If the entity has been despawned while this `EntityWorldMut` is still alive.266/// - If [`AppTypeRegistry`] is not present in the [`World`](crate::world::World).267///268/// # Note269///270/// Prefer to use the typed [`EntityWorldMut::remove`] if possible. Removing a reflected component271/// is much slower.272pub fn remove_reflect(&mut self, component_type_path: Cow<'static, str>) -> &mut Self {273self.assert_not_despawned();274self.resource_scope(|entity, registry: Mut<AppTypeRegistry>| {275let type_registry = ®istry.as_ref().read();276remove_reflect_with_registry_ref(entity, type_registry, component_type_path);277});278self279}280281/// Same as [`remove_reflect`](EntityWorldMut::remove_reflect), but using282/// the `T` resource as type registry instead of `AppTypeRegistry`.283///284/// If the given type is a bundle, it will remove any components in that bundle regardless if the entity285/// contains all the components.286///287/// Does nothing if the type is a component and the entity does not have a component of the same type,288/// if the type is a bundle and the entity does not contain any of the components in the bundle,289/// or if [`AppTypeRegistry`] does not contain the reflection data for the given component.290///291/// # Panics292///293/// - If the entity has been despawned while this `EntityWorldMut` is still alive.294/// - If [`AppTypeRegistry`] is not present in the [`World`](crate::world::World).295pub fn remove_reflect_with_registry<T: Resource + AsRef<TypeRegistry>>(296&mut self,297component_type_path: Cow<'static, str>,298) -> &mut Self {299self.assert_not_despawned();300self.resource_scope(|entity, registry: Mut<T>| {301let type_registry = registry.as_ref().as_ref();302remove_reflect_with_registry_ref(entity, type_registry, component_type_path);303});304self305}306307/// Takes from the entity the component or bundle with the given type path registered in [`AppTypeRegistry`].308///309/// Does nothing and returns None if the type is a component and the entity does not have a component of the same type,310/// if the type is a bundle and the entity does not contain **every** component in the bundle,311/// or if [`AppTypeRegistry`] does not contain the reflection data for the given component.312///313/// # Panics314///315/// - If the entity has been despawned while this `EntityWorldMut` is still alive.316/// - If [`AppTypeRegistry`] is not present in the [`World`](crate::world::World).317///318/// # Note319///320/// Prefer to use the typed [`EntityWorldMut::take`] if possible. Taking a reflected component321/// is much slower.322pub fn take_reflect(323&mut self,324component_type_path: Cow<'static, str>,325) -> Option<Box<dyn Reflect>> {326self.assert_not_despawned();327self.resource_scope(|entity, registry: Mut<AppTypeRegistry>| {328let type_registry = ®istry.as_ref().read();329take_reflect_with_registry_ref(entity, type_registry, component_type_path)330})331}332333/// Same as [`take_reflect`](EntityWorldMut::take_reflect), but using334/// the `T` resource as type registry instead of `AppTypeRegistry`.335///336/// Does nothing and returns None if the type is a component and the entity does not have a component of the same type,337/// if the type is a bundle and the entity does not contain **every** component in the bundle,338/// or if [`AppTypeRegistry`] does not contain the reflection data for the given component.339///340/// # Panics341///342/// - If the entity has been despawned while this `EntityWorldMut` is still alive.343/// - If [`AppTypeRegistry`] is not present in the [`World`](crate::world::World).344pub fn take_reflect_with_registry<T: Resource + AsRef<TypeRegistry>>(345&mut self,346component_type_path: Cow<'static, str>,347) -> Option<Box<dyn Reflect>> {348self.assert_not_despawned();349self.resource_scope(|entity, registry: Mut<T>| {350let type_registry = registry.as_ref().as_ref();351take_reflect_with_registry_ref(entity, type_registry, component_type_path)352})353}354}355356/// Helper function to add a reflect component or bundle to a given entity357fn insert_reflect_with_registry_ref(358entity: &mut EntityWorldMut,359type_registry: &TypeRegistry,360component: Box<dyn PartialReflect>,361) {362let type_info = component363.get_represented_type_info()364.expect("component should represent a type.");365let type_path = type_info.type_path();366let Some(type_registration) = type_registry.get(type_info.type_id()) else {367panic!("`{type_path}` should be registered in type registry via `App::register_type<{type_path}>`");368};369370if let Some(reflect_component) = type_registration.data::<ReflectComponent>() {371reflect_component.insert(entity, component.as_partial_reflect(), type_registry);372} else if let Some(reflect_bundle) = type_registration.data::<ReflectBundle>() {373reflect_bundle.insert(entity, component.as_partial_reflect(), type_registry);374} else {375panic!("`{type_path}` should have #[reflect(Component)] or #[reflect(Bundle)]");376}377}378379/// Helper function to remove a reflect component or bundle from a given entity380fn remove_reflect_with_registry_ref(381entity: &mut EntityWorldMut,382type_registry: &TypeRegistry,383component_type_path: Cow<'static, str>,384) {385let Some(type_registration) = type_registry.get_with_type_path(&component_type_path) else {386return;387};388if let Some(reflect_component) = type_registration.data::<ReflectComponent>() {389reflect_component.remove(entity);390} else if let Some(reflect_bundle) = type_registration.data::<ReflectBundle>() {391reflect_bundle.remove(entity);392}393}394395/// Helper function to take a reflect component or bundle from a given entity396fn take_reflect_with_registry_ref(397entity: &mut EntityWorldMut,398type_registry: &TypeRegistry,399component_type_path: Cow<'static, str>,400) -> Option<Box<dyn Reflect>> {401let type_registration = type_registry.get_with_type_path(&component_type_path)?;402if let Some(reflect_component) = type_registration.data::<ReflectComponent>() {403reflect_component.take(entity)404} else if let Some(reflect_bundle) = type_registration.data::<ReflectBundle>() {405reflect_bundle.take(entity)406} else {407None408}409}410411#[cfg(test)]412mod tests {413use crate::{414bundle::Bundle,415component::Component,416prelude::{AppTypeRegistry, ReflectComponent},417reflect::{ReflectBundle, ReflectCommandExt},418system::{Commands, SystemState},419world::World,420};421use alloc::{borrow::ToOwned, boxed::Box};422use bevy_ecs_macros::Resource;423use bevy_reflect::{PartialReflect, Reflect, TypeRegistry};424425#[derive(Resource)]426struct TypeRegistryResource {427type_registry: TypeRegistry,428}429430impl AsRef<TypeRegistry> for TypeRegistryResource {431fn as_ref(&self) -> &TypeRegistry {432&self.type_registry433}434}435436#[derive(Component, Reflect, Default, PartialEq, Eq, Debug)]437#[reflect(Component)]438struct ComponentA(u32);439440#[derive(Component, Reflect, Default, PartialEq, Eq, Debug)]441#[reflect(Component)]442struct ComponentB(u32);443444#[derive(Bundle, Reflect, Default, Debug, PartialEq)]445#[reflect(Bundle)]446struct BundleA {447a: ComponentA,448b: ComponentB,449}450451#[test]452fn insert_reflected() {453let mut world = World::new();454455let type_registry = AppTypeRegistry::default();456{457let mut registry = type_registry.write();458registry.register::<ComponentA>();459registry.register_type_data::<ComponentA, ReflectComponent>();460}461world.insert_resource(type_registry);462463let mut system_state: SystemState<Commands> = SystemState::new(&mut world);464let mut commands = system_state.get_mut(&mut world);465466let entity = commands.spawn_empty().id();467let entity2 = commands.spawn_empty().id();468let entity3 = commands.spawn_empty().id();469470let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box<dyn PartialReflect>;471let boxed_reflect_component_a_clone = boxed_reflect_component_a.reflect_clone().unwrap();472let boxed_reflect_component_a_dynamic = boxed_reflect_component_a.to_dynamic();473474commands475.entity(entity)476.insert_reflect(boxed_reflect_component_a);477commands478.entity(entity2)479.insert_reflect(boxed_reflect_component_a_clone.into_partial_reflect());480commands481.entity(entity3)482.insert_reflect(boxed_reflect_component_a_dynamic);483system_state.apply(&mut world);484485assert_eq!(486world.entity(entity).get::<ComponentA>(),487world.entity(entity2).get::<ComponentA>(),488);489assert_eq!(490world.entity(entity).get::<ComponentA>(),491world.entity(entity3).get::<ComponentA>(),492);493}494495#[test]496fn insert_reflected_with_registry() {497let mut world = World::new();498499let mut type_registry = TypeRegistryResource {500type_registry: TypeRegistry::new(),501};502503type_registry.type_registry.register::<ComponentA>();504type_registry505.type_registry506.register_type_data::<ComponentA, ReflectComponent>();507world.insert_resource(type_registry);508509let mut system_state: SystemState<Commands> = SystemState::new(&mut world);510let mut commands = system_state.get_mut(&mut world);511512let entity = commands.spawn_empty().id();513514let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box<dyn PartialReflect>;515516commands517.entity(entity)518.insert_reflect_with_registry::<TypeRegistryResource>(boxed_reflect_component_a);519system_state.apply(&mut world);520521assert_eq!(522world.entity(entity).get::<ComponentA>(),523Some(&ComponentA(916))524);525}526527#[test]528fn remove_reflected() {529let mut world = World::new();530531let type_registry = AppTypeRegistry::default();532{533let mut registry = type_registry.write();534registry.register::<ComponentA>();535registry.register_type_data::<ComponentA, ReflectComponent>();536}537world.insert_resource(type_registry);538539let mut system_state: SystemState<Commands> = SystemState::new(&mut world);540let mut commands = system_state.get_mut(&mut world);541542let entity = commands.spawn(ComponentA(0)).id();543544let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box<dyn Reflect>;545546commands547.entity(entity)548.remove_reflect(boxed_reflect_component_a.reflect_type_path().to_owned());549system_state.apply(&mut world);550551assert_eq!(world.entity(entity).get::<ComponentA>(), None);552}553554#[test]555fn remove_reflected_with_registry() {556let mut world = World::new();557558let mut type_registry = TypeRegistryResource {559type_registry: TypeRegistry::new(),560};561562type_registry.type_registry.register::<ComponentA>();563type_registry564.type_registry565.register_type_data::<ComponentA, ReflectComponent>();566world.insert_resource(type_registry);567568let mut system_state: SystemState<Commands> = SystemState::new(&mut world);569let mut commands = system_state.get_mut(&mut world);570571let entity = commands.spawn(ComponentA(0)).id();572573let boxed_reflect_component_a = Box::new(ComponentA(916)) as Box<dyn Reflect>;574575commands576.entity(entity)577.remove_reflect_with_registry::<TypeRegistryResource>(578boxed_reflect_component_a.reflect_type_path().to_owned(),579);580system_state.apply(&mut world);581582assert_eq!(world.entity(entity).get::<ComponentA>(), None);583}584585#[test]586fn insert_reflect_bundle() {587let mut world = World::new();588589let type_registry = AppTypeRegistry::default();590{591let mut registry = type_registry.write();592registry.register::<BundleA>();593registry.register_type_data::<BundleA, ReflectBundle>();594}595world.insert_resource(type_registry);596597let mut system_state: SystemState<Commands> = SystemState::new(&mut world);598let mut commands = system_state.get_mut(&mut world);599600let entity = commands.spawn_empty().id();601let bundle = Box::new(BundleA {602a: ComponentA(31),603b: ComponentB(20),604}) as Box<dyn PartialReflect>;605commands.entity(entity).insert_reflect(bundle);606607system_state.apply(&mut world);608609assert_eq!(world.get::<ComponentA>(entity), Some(&ComponentA(31)));610assert_eq!(world.get::<ComponentB>(entity), Some(&ComponentB(20)));611}612613#[test]614fn insert_reflect_bundle_with_registry() {615let mut world = World::new();616617let mut type_registry = TypeRegistryResource {618type_registry: TypeRegistry::new(),619};620621type_registry.type_registry.register::<BundleA>();622type_registry623.type_registry624.register_type_data::<BundleA, ReflectBundle>();625world.insert_resource(type_registry);626627let mut system_state: SystemState<Commands> = SystemState::new(&mut world);628let mut commands = system_state.get_mut(&mut world);629630let entity = commands.spawn_empty().id();631let bundle = Box::new(BundleA {632a: ComponentA(31),633b: ComponentB(20),634}) as Box<dyn PartialReflect>;635636commands637.entity(entity)638.insert_reflect_with_registry::<TypeRegistryResource>(bundle);639system_state.apply(&mut world);640641assert_eq!(world.get::<ComponentA>(entity), Some(&ComponentA(31)));642assert_eq!(world.get::<ComponentB>(entity), Some(&ComponentB(20)));643}644645#[test]646fn remove_reflected_bundle() {647let mut world = World::new();648649let type_registry = AppTypeRegistry::default();650{651let mut registry = type_registry.write();652registry.register::<BundleA>();653registry.register_type_data::<BundleA, ReflectBundle>();654}655world.insert_resource(type_registry);656657let mut system_state: SystemState<Commands> = SystemState::new(&mut world);658let mut commands = system_state.get_mut(&mut world);659660let entity = commands661.spawn(BundleA {662a: ComponentA(31),663b: ComponentB(20),664})665.id();666667let boxed_reflect_bundle_a = Box::new(BundleA {668a: ComponentA(1),669b: ComponentB(23),670}) as Box<dyn Reflect>;671672commands673.entity(entity)674.remove_reflect(boxed_reflect_bundle_a.reflect_type_path().to_owned());675system_state.apply(&mut world);676677assert_eq!(world.entity(entity).get::<ComponentA>(), None);678assert_eq!(world.entity(entity).get::<ComponentB>(), None);679}680681#[test]682fn remove_reflected_bundle_with_registry() {683let mut world = World::new();684685let mut type_registry = TypeRegistryResource {686type_registry: TypeRegistry::new(),687};688689type_registry.type_registry.register::<BundleA>();690type_registry691.type_registry692.register_type_data::<BundleA, ReflectBundle>();693world.insert_resource(type_registry);694695let mut system_state: SystemState<Commands> = SystemState::new(&mut world);696let mut commands = system_state.get_mut(&mut world);697698let entity = commands699.spawn(BundleA {700a: ComponentA(31),701b: ComponentB(20),702})703.id();704705let boxed_reflect_bundle_a = Box::new(BundleA {706a: ComponentA(1),707b: ComponentB(23),708}) as Box<dyn Reflect>;709710commands711.entity(entity)712.remove_reflect_with_registry::<TypeRegistryResource>(713boxed_reflect_bundle_a.reflect_type_path().to_owned(),714);715system_state.apply(&mut world);716717assert_eq!(world.entity(entity).get::<ComponentA>(), None);718assert_eq!(world.entity(entity).get::<ComponentB>(), None);719}720}721722723