diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index 80e60a8860..d083901ccc 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -2400,7 +2400,7 @@ impl Components { /// * [`World::component_id()`] #[inline] pub fn valid_component_id(&self) -> Option { - self.get_id(TypeId::of::()) + self.get_valid_id(TypeId::of::()) } /// Type-erased equivalent of [`Components::valid_resource_id()`]. @@ -2431,7 +2431,7 @@ impl Components { /// * [`Components::get_resource_id()`] #[inline] pub fn valid_resource_id(&self) -> Option { - self.get_resource_id(TypeId::of::()) + self.get_valid_resource_id(TypeId::of::()) } /// Type-erased equivalent of [`Components::component_id()`]. diff --git a/crates/bevy_ecs/src/entity/clone_entities.rs b/crates/bevy_ecs/src/entity/clone_entities.rs index a7a1f84403..b124055d16 100644 --- a/crates/bevy_ecs/src/entity/clone_entities.rs +++ b/crates/bevy_ecs/src/entity/clone_entities.rs @@ -705,7 +705,7 @@ impl<'w> EntityClonerBuilder<'w> { /// [`deny_all`](`Self::deny_all`) before calling any of the `allow` methods. pub fn allow_by_type_ids(&mut self, ids: impl IntoIterator) -> &mut Self { for type_id in ids { - if let Some(id) = self.world.components().get_id(type_id) { + if let Some(id) = self.world.components().get_valid_id(type_id) { self.filter_allow(id); } } @@ -740,7 +740,7 @@ impl<'w> EntityClonerBuilder<'w> { /// Extends the list of components that shouldn't be cloned by type ids. pub fn deny_by_type_ids(&mut self, ids: impl IntoIterator) -> &mut Self { for type_id in ids { - if let Some(id) = self.world.components().get_id(type_id) { + if let Some(id) = self.world.components().get_valid_id(type_id) { self.filter_deny(id); } } @@ -762,7 +762,7 @@ impl<'w> EntityClonerBuilder<'w> { &mut self, clone_behavior: ComponentCloneBehavior, ) -> &mut Self { - if let Some(id) = self.world.components().component_id::() { + if let Some(id) = self.world.components().valid_component_id::() { self.entity_cloner .clone_behavior_overrides .insert(id, clone_behavior); @@ -787,7 +787,7 @@ impl<'w> EntityClonerBuilder<'w> { /// Removes a previously set override of [`ComponentCloneBehavior`] for a component in this builder. pub fn remove_clone_behavior_override(&mut self) -> &mut Self { - if let Some(id) = self.world.components().component_id::() { + if let Some(id) = self.world.components().valid_component_id::() { self.entity_cloner.clone_behavior_overrides.remove(&id); } self diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 9842ee54e3..a30c4d3419 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -3279,7 +3279,11 @@ impl<'w> FilteredEntityRef<'w> { /// Returns `None` if the entity does not have a component of type `T`. #[inline] pub fn get(&self) -> Option<&'w T> { - let id = self.entity.world().components().get_id(TypeId::of::())?; + let id = self + .entity + .world() + .components() + .get_valid_id(TypeId::of::())?; self.access .has_component_read(id) // SAFETY: We have read access @@ -3293,7 +3297,11 @@ impl<'w> FilteredEntityRef<'w> { /// Returns `None` if the entity does not have a component of type `T`. #[inline] pub fn get_ref(&self) -> Option> { - let id = self.entity.world().components().get_id(TypeId::of::())?; + let id = self + .entity + .world() + .components() + .get_valid_id(TypeId::of::())?; self.access .has_component_read(id) // SAFETY: We have read access @@ -3305,7 +3313,11 @@ impl<'w> FilteredEntityRef<'w> { /// detection in custom runtimes. #[inline] pub fn get_change_ticks(&self) -> Option { - let id = self.entity.world().components().get_id(TypeId::of::())?; + let id = self + .entity + .world() + .components() + .get_valid_id(TypeId::of::())?; self.access .has_component_read(id) // SAFETY: We have read access @@ -3637,7 +3649,11 @@ impl<'w> FilteredEntityMut<'w> { /// Returns `None` if the entity does not have a component of type `T`. #[inline] pub fn get_mut>(&mut self) -> Option> { - let id = self.entity.world().components().get_id(TypeId::of::())?; + let id = self + .entity + .world() + .components() + .get_valid_id(TypeId::of::())?; self.access .has_component_write(id) // SAFETY: We have write access @@ -3665,7 +3681,11 @@ impl<'w> FilteredEntityMut<'w> { /// - `T` must be a mutable component #[inline] pub unsafe fn into_mut_assume_mutable(self) -> Option> { - let id = self.entity.world().components().get_id(TypeId::of::())?; + let id = self + .entity + .world() + .components() + .get_valid_id(TypeId::of::())?; self.access .has_component_write(id) // SAFETY: @@ -3895,7 +3915,7 @@ where C: Component, { let components = self.entity.world().components(); - let id = components.component_id::()?; + let id = components.valid_component_id::()?; if bundle_contains_component::(components, id) { None } else { @@ -3915,7 +3935,7 @@ where C: Component, { let components = self.entity.world().components(); - let id = components.component_id::()?; + let id = components.valid_component_id::()?; if bundle_contains_component::(components, id) { None } else { @@ -3995,7 +4015,11 @@ where /// detection in custom runtimes. #[inline] pub fn get_change_ticks(&self) -> Option { - let component_id = self.entity.world().components().get_id(TypeId::of::())?; + let component_id = self + .entity + .world() + .components() + .get_valid_id(TypeId::of::())?; let components = self.entity.world().components(); (!bundle_contains_component::(components, component_id)) .then(|| { @@ -4164,7 +4188,7 @@ where C: Component, { let components = self.entity.world().components(); - let id = components.component_id::()?; + let id = components.valid_component_id::()?; if bundle_contains_component::(components, id) { None } else { @@ -4747,7 +4771,7 @@ mod tests { let entity = world.spawn(TestComponent(42)).id(); let component_id = world .components() - .get_id(core::any::TypeId::of::()) + .get_valid_id(core::any::TypeId::of::()) .unwrap(); let entity = world.entity(entity); @@ -4764,7 +4788,7 @@ mod tests { let entity = world.spawn(TestComponent(42)).id(); let component_id = world .components() - .get_id(core::any::TypeId::of::()) + .get_valid_id(core::any::TypeId::of::()) .unwrap(); let mut entity_mut = world.entity_mut(entity); diff --git a/crates/bevy_ecs/src/world/filtered_resource.rs b/crates/bevy_ecs/src/world/filtered_resource.rs index a9fac308fa..ed3672bef9 100644 --- a/crates/bevy_ecs/src/world/filtered_resource.rs +++ b/crates/bevy_ecs/src/world/filtered_resource.rs @@ -157,7 +157,7 @@ impl<'w, 's> FilteredResources<'w, 's> { let component_id = self .world .components() - .resource_id::() + .valid_resource_id::() .ok_or(ResourceFetchError::NotRegistered)?; if !self.access.has_resource_read(component_id) { return Err(ResourceFetchError::NoResourceAccess(component_id)); @@ -474,7 +474,7 @@ impl<'w, 's> FilteredResourcesMut<'w, 's> { let component_id = self .world .components() - .resource_id::() + .valid_resource_id::() .ok_or(ResourceFetchError::NotRegistered)?; // SAFETY: THe caller ensures that there are no conflicting borrows. unsafe { self.get_mut_by_id_unchecked(component_id) } diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 8cd558e8db..4172f0b31d 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -531,7 +531,7 @@ impl World { /// Retrieves the [required components](RequiredComponents) for the given component type, if it exists. pub fn get_required_components(&self) -> Option<&RequiredComponents> { - let id = self.components().component_id::()?; + let id = self.components().valid_component_id::()?; let component_info = self.components().get_info(id)?; Some(component_info.required_components()) } @@ -1623,7 +1623,7 @@ impl World { /// since the last call to [`World::clear_trackers`]. pub fn removed(&self) -> impl Iterator + '_ { self.components - .get_id(TypeId::of::()) + .get_valid_id(TypeId::of::()) .map(|component_id| self.removed_with_id(component_id)) .into_iter() .flatten() @@ -1772,7 +1772,7 @@ impl World { /// Removes the resource of a given type and returns it, if it exists. Otherwise returns `None`. #[inline] pub fn remove_resource(&mut self) -> Option { - let component_id = self.components.get_resource_id(TypeId::of::())?; + let component_id = self.components.get_valid_resource_id(TypeId::of::())?; let (ptr, _, _) = self.storages.resources.get_mut(component_id)?.remove()?; // SAFETY: `component_id` was gotten via looking up the `R` type unsafe { Some(ptr.read::()) } @@ -1791,7 +1791,7 @@ impl World { /// thread than where the value was inserted from. #[inline] pub fn remove_non_send_resource(&mut self) -> Option { - let component_id = self.components.get_resource_id(TypeId::of::())?; + let component_id = self.components.get_valid_resource_id(TypeId::of::())?; let (ptr, _, _) = self .storages .non_send_resources @@ -1805,7 +1805,7 @@ impl World { #[inline] pub fn contains_resource(&self) -> bool { self.components - .get_resource_id(TypeId::of::()) + .get_valid_resource_id(TypeId::of::()) .and_then(|component_id| self.storages.resources.get(component_id)) .is_some_and(ResourceData::is_present) } @@ -1823,7 +1823,7 @@ impl World { #[inline] pub fn contains_non_send(&self) -> bool { self.components - .get_resource_id(TypeId::of::()) + .get_valid_resource_id(TypeId::of::()) .and_then(|component_id| self.storages.non_send_resources.get(component_id)) .is_some_and(ResourceData::is_present) } @@ -1846,7 +1846,7 @@ impl World { /// was called. pub fn is_resource_added(&self) -> bool { self.components - .get_resource_id(TypeId::of::()) + .get_valid_resource_id(TypeId::of::()) .is_some_and(|component_id| self.is_resource_added_by_id(component_id)) } @@ -1877,7 +1877,7 @@ impl World { /// was called. pub fn is_resource_changed(&self) -> bool { self.components - .get_resource_id(TypeId::of::()) + .get_valid_resource_id(TypeId::of::()) .is_some_and(|component_id| self.is_resource_changed_by_id(component_id)) } @@ -1902,7 +1902,7 @@ impl World { /// Retrieves the change ticks for the given resource. pub fn get_resource_change_ticks(&self) -> Option { self.components - .get_resource_id(TypeId::of::()) + .get_valid_resource_id(TypeId::of::()) .and_then(|component_id| self.get_resource_change_ticks_by_id(component_id)) } @@ -2558,7 +2558,7 @@ impl World { let last_change_tick = self.last_change_tick(); let change_tick = self.change_tick(); - let component_id = self.components.get_resource_id(TypeId::of::())?; + let component_id = self.components.get_valid_resource_id(TypeId::of::())?; let (ptr, mut ticks, mut caller) = self .storages .resources @@ -3750,7 +3750,7 @@ mod tests { world.insert_resource(TestResource(42)); let component_id = world .components() - .get_resource_id(TypeId::of::()) + .get_valid_resource_id(TypeId::of::()) .unwrap(); let resource = world.get_resource_by_id(component_id).unwrap(); @@ -3766,7 +3766,7 @@ mod tests { world.insert_resource(TestResource(42)); let component_id = world .components() - .get_resource_id(TypeId::of::()) + .get_valid_resource_id(TypeId::of::()) .unwrap(); { diff --git a/crates/bevy_ecs/src/world/reflect.rs b/crates/bevy_ecs/src/world/reflect.rs index fdd8b28142..5ecdf88156 100644 --- a/crates/bevy_ecs/src/world/reflect.rs +++ b/crates/bevy_ecs/src/world/reflect.rs @@ -70,7 +70,7 @@ impl World { entity: Entity, type_id: TypeId, ) -> Result<&dyn Reflect, GetComponentReflectError> { - let Some(component_id) = self.components().get_id(type_id) else { + let Some(component_id) = self.components().get_valid_id(type_id) else { return Err(GetComponentReflectError::NoCorrespondingComponentId( type_id, )); @@ -158,7 +158,7 @@ impl World { )); }; - let Some(component_id) = self.components().get_id(type_id) else { + let Some(component_id) = self.components().get_valid_id(type_id) else { return Err(GetComponentReflectError::NoCorrespondingComponentId( type_id, )); diff --git a/crates/bevy_ecs/src/world/unsafe_world_cell.rs b/crates/bevy_ecs/src/world/unsafe_world_cell.rs index 3f8298cd29..1959f3e5f3 100644 --- a/crates/bevy_ecs/src/world/unsafe_world_cell.rs +++ b/crates/bevy_ecs/src/world/unsafe_world_cell.rs @@ -401,7 +401,7 @@ impl<'w> UnsafeWorldCell<'w> { /// - no mutable reference to the resource exists at the same time #[inline] pub unsafe fn get_resource(self) -> Option<&'w R> { - let component_id = self.components().get_resource_id(TypeId::of::())?; + let component_id = self.components().get_valid_resource_id(TypeId::of::())?; // SAFETY: caller ensures `self` has permission to access the resource // caller also ensure that no mutable reference to the resource exists unsafe { @@ -419,7 +419,7 @@ impl<'w> UnsafeWorldCell<'w> { /// - no mutable reference to the resource exists at the same time #[inline] pub unsafe fn get_resource_ref(self) -> Option> { - let component_id = self.components().get_resource_id(TypeId::of::())?; + let component_id = self.components().get_valid_resource_id(TypeId::of::())?; // SAFETY: caller ensures `self` has permission to access the resource // caller also ensures that no mutable reference to the resource exists @@ -471,7 +471,7 @@ impl<'w> UnsafeWorldCell<'w> { /// - no mutable reference to the resource exists at the same time #[inline] pub unsafe fn get_non_send_resource(self) -> Option<&'w R> { - let component_id = self.components().get_resource_id(TypeId::of::())?; + let component_id = self.components().get_valid_resource_id(TypeId::of::())?; // SAFETY: caller ensures that `self` has permission to access `R` // caller ensures that no mutable reference exists to `R` unsafe { @@ -514,7 +514,7 @@ impl<'w> UnsafeWorldCell<'w> { #[inline] pub unsafe fn get_resource_mut(self) -> Option> { self.assert_allows_mutable_access(); - let component_id = self.components().get_resource_id(TypeId::of::())?; + let component_id = self.components().get_valid_resource_id(TypeId::of::())?; // SAFETY: // - caller ensures `self` has permission to access the resource mutably // - caller ensures no other references to the resource exist @@ -578,7 +578,7 @@ impl<'w> UnsafeWorldCell<'w> { #[inline] pub unsafe fn get_non_send_resource_mut(self) -> Option> { self.assert_allows_mutable_access(); - let component_id = self.components().get_resource_id(TypeId::of::())?; + let component_id = self.components().get_valid_resource_id(TypeId::of::())?; // SAFETY: // - caller ensures that `self` has permission to access the resource // - caller ensures that the resource is unaliased @@ -826,7 +826,7 @@ impl<'w> UnsafeEntityCell<'w> { /// - no other mutable references to the component exist at the same time #[inline] pub unsafe fn get(self) -> Option<&'w T> { - let component_id = self.world.components().get_id(TypeId::of::())?; + let component_id = self.world.components().get_valid_id(TypeId::of::())?; // SAFETY: // - `storage_type` is correct (T component_id + T::STORAGE_TYPE) // - `location` is valid @@ -852,7 +852,7 @@ impl<'w> UnsafeEntityCell<'w> { pub unsafe fn get_ref(self) -> Option> { let last_change_tick = self.last_run; let change_tick = self.this_run; - let component_id = self.world.components().get_id(TypeId::of::())?; + let component_id = self.world.components().get_valid_id(TypeId::of::())?; // SAFETY: // - `storage_type` is correct (T component_id + T::STORAGE_TYPE) @@ -884,7 +884,7 @@ impl<'w> UnsafeEntityCell<'w> { /// - no other mutable references to the component exist at the same time #[inline] pub unsafe fn get_change_ticks(self) -> Option { - let component_id = self.world.components().get_id(TypeId::of::())?; + let component_id = self.world.components().get_valid_id(TypeId::of::())?; // SAFETY: // - entity location is valid @@ -968,7 +968,7 @@ impl<'w> UnsafeEntityCell<'w> { ) -> Option> { self.world.assert_allows_mutable_access(); - let component_id = self.world.components().get_id(TypeId::of::())?; + let component_id = self.world.components().get_valid_id(TypeId::of::())?; // SAFETY: // - `storage_type` is correct diff --git a/crates/bevy_remote/src/builtin_methods.rs b/crates/bevy_remote/src/builtin_methods.rs index 18c85d3eec..2f7b912a3d 100644 --- a/crates/bevy_remote/src/builtin_methods.rs +++ b/crates/bevy_remote/src/builtin_methods.rs @@ -570,7 +570,8 @@ pub fn process_remote_get_watching_request( ); continue; }; - let Some(component_id) = world.components().get_id(type_registration.type_id()) else { + let Some(component_id) = world.components().get_valid_id(type_registration.type_id()) + else { let err = BrpError::component_error(format!("Unknown component: `{component_path}`")); if strict { return Err(err); @@ -1304,7 +1305,7 @@ fn get_component_ids( let type_id = type_registration.type_id(); world .components() - .get_id(type_id) + .get_valid_id(type_id) .map(|component_id| (type_id, component_id)) }); if let Some((type_id, component_id)) = maybe_component_tuple { diff --git a/crates/bevy_scene/src/dynamic_scene_builder.rs b/crates/bevy_scene/src/dynamic_scene_builder.rs index c9e594107e..ee0b15847a 100644 --- a/crates/bevy_scene/src/dynamic_scene_builder.rs +++ b/crates/bevy_scene/src/dynamic_scene_builder.rs @@ -350,7 +350,7 @@ impl<'w> DynamicSceneBuilder<'w> { let original_world_dqf_id = self .original_world .components() - .get_resource_id(TypeId::of::()); + .get_valid_resource_id(TypeId::of::()); let type_registry = self.original_world.resource::().read();