FyroxEngine/Fyrox · error
Resource type mismatch. Expected
Error message
Resource type mismatch. Expected: {expected}. Found: {type_uuid} What it means
The From<UntypedResource> impl for Resource<T> converts an untyped resource into a typed one, but panics if the resource's actual type UUID differs from the expected T::type_uuid. This is a hard type check: the library prefers failing fast over silently wrapping a resource of the wrong type.
Solutions
- Check untyped.resource_state/type_uuid before conversion, or use try_cast / cast::<T>() which returns Option instead of panicking.
- Request the resource with the correct concrete type via resource_manager.request::<Texture>(path).
- Fix the path/extension so the resource loads as the intended type.
Example fix
// before
let texture: TextureResource = model_untyped.into(); // panics on mismatch
// after
if let Some(texture) = model_untyped.cast::<Texture>() {
// use texture
} Defensive patterns
Strategy: type-guard
Validate before calling
let ok = untyped.type_uuid() == Some(<Texture as Reflect>::type_info().type_uuid);
Type guard
fn is_same_type<T: Reflect>(untyped: &UntypedResource) -> bool {
untyped.type_uuid() == Some(<T as Reflect>::type_info().type_uuid)
} Prevention
- Always use UntypedResource::cast::<T>() (returns Option) instead of From/into for conversions.
- Request resources as concrete types via resource_manager.request::<T>() rather than untyped + cast.
- Verify asset extensions map to the intended loader/type when setting up paths.
When it happens
Trigger: Calling .into()/Resource::<T>::from(untyped) where untyped holds e.g. a Model while T is Texture; passing a resource loaded from a file whose extension/format does not match T.
Common situations: requesting resources generically then casting without checking; data files renamed/misconfigured so the wrong loader produced the resource; API changes where the expected resource type changed.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cast to failed!
- Path may not start with ..
- Unable to get a resource of type
- Unable to get a resource of type
- Unable to get a resource of type
AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10).
Data as JSON: /api/errors/0e739799262e5d95.
Report an issue: GitHub.
Appendix: source
Thrown at fyrox-resource/src/lib.rs:494
impl<T> From<Uuid> for Resource<T>
where
T: TypedResourceData,
{
fn from(uuid: Uuid) -> Self {
UntypedResource::from(uuid).into()
}
}
impl<T> From<UntypedResource> for Resource<T>
where
T: TypedResourceData,
{
#[inline]
fn from(untyped: UntypedResource) -> Self {
if let Some(type_uuid) = untyped.type_uuid() {
let expected = <T as Reflect>::type_info().type_uuid;
if type_uuid != expected {
panic!("Resource type mismatch. Expected: {expected}. Found: {type_uuid}");
}
}
Self {
untyped,
phantom: Default::default(),
}
}
}
#[allow(clippy::from_over_into)]
impl<T> Into<UntypedResource> for Resource<T>
where
T: TypedResourceData,
{
#[inline]
fn into(self) -> UntypedResource {
self.untyped
}View on GitHub (pinned to 76c91aad8e)