diff --git a/crates/bevy_reflect/src/type_registry.rs b/crates/bevy_reflect/src/type_registry.rs index 8118a7824e..a67678e836 100644 --- a/crates/bevy_reflect/src/type_registry.rs +++ b/crates/bevy_reflect/src/type_registry.rs @@ -211,7 +211,7 @@ impl TypeRegistry { /// If the short type path is ambiguous, or if no type with the given path /// has been registered, returns `None`. /// - /// [type path]: TypePath::short_type_path + /// [short type path]: TypePath::short_type_path pub fn get_with_short_type_path(&self, short_type_path: &str) -> Option<&TypeRegistration> { self.short_path_to_id .get(short_type_path) @@ -224,7 +224,7 @@ impl TypeRegistry { /// If the short type path is ambiguous, or if no type with the given path /// has been registered, returns `None`. /// - /// [type path]: TypePath::short_type_path + /// [short type path]: TypePath::short_type_path pub fn get_with_short_type_path_mut( &mut self, short_type_path: &str, @@ -234,6 +234,32 @@ impl TypeRegistry { .and_then(|id| self.registrations.get_mut(id)) } + /// Returns `true` if the given [short type path] is ambiguous, that is, it matches multiple registered types. + /// + /// # Example + /// ``` + /// # use bevy_reflect::TypeRegistry; + /// # mod foo { + /// # use bevy_reflect::Reflect; + /// # #[derive(Reflect)] + /// # pub struct MyType; + /// # } + /// # mod bar { + /// # use bevy_reflect::Reflect; + /// # #[derive(Reflect)] + /// # pub struct MyType; + /// # } + /// let mut type_registry = TypeRegistry::default(); + /// type_registry.register::(); + /// type_registry.register::(); + /// assert_eq!(type_registry.is_ambiguous("MyType"), true); + /// ``` + /// + /// [short type path]: TypePath::short_type_path + pub fn is_ambiguous(&self, short_type_path: &str) -> bool { + self.ambiguous_names.contains(short_type_path) + } + /// Returns a reference to the [`TypeData`] of type `T` associated with the given [`TypeId`]. /// /// The returned value may be used to downcast [`Reflect`] trait objects to