{"record":{"id":"b6c40dc25f43d59c","repo":"FyroxEngine/Fyrox","slug":"unable-to-add-a-resource-of-type-needed-type-uuid","errorCode":null,"errorMessage":"Unable to add a resource of type {needed_type_uuid} from resource UUID {}! The resource is loaded but its actual data has type {type_uuid}!","messagePattern":"Unable to add a resource of type (.+?) from resource UUID (.+?)! The resource is loaded but its actual data has type (.+?)!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"fyrox-resource/src/manager.rs","lineNumber":700,"sourceCode":"            }\n        }\n    }\n\n    /// Add the given resource to the resource manager, based on the resource's UUID,\n    /// without initiating the loading of the resource. The given resource is modified\n    /// to be a reference to the shared data of an existing resource with the same UUID.\n    pub fn add_resource<T>(&self, resource: &mut Resource<T>)\n    where\n        T: TypedResourceData,\n    {\n        let mut state = self.state();\n\n        state.add_resource(&mut resource.untyped);\n\n        if let Some(type_uuid) = resource.untyped.type_uuid_non_blocking() {\n            let needed_type_uuid = <T as Reflect>::type_info().type_uuid;\n            if type_uuid != needed_type_uuid {\n                panic!(\n                    \"Unable to add a resource of type {needed_type_uuid} from resource UUID {}! The resource is \\\n                    loaded but its actual data has type {type_uuid}!\",\n                    resource.resource_uuid(),\n                );\n            }\n        }\n    }\n\n    /// The same as [`Self::request`], but returns [`None`] if type UUID of `T` does not match the actual type UUID\n    /// of the resource.\n    ///\n    /// ## Panic\n    ///\n    /// This method does not panic.\n    pub fn try_request<T>(&self, path: impl AsRef<Path>) -> Option<Resource<T>>\n    where\n        T: TypedResourceData,\n    {","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-resource/src/manager.rs#L682-L718","documentation":"ResourceManager::add_resource<T>(resource) registers a typed resource and verifies, after adding, that the untyped resource's data type UUID matches T. A mismatch means the caller wrapped the wrong data type in the typed handle, so it panics instead of storing a lying entry.","triggerScenarios":"Calling resource_manager.add_resource::<T>(...) (e.g. add_texture-like wrappers) with a Resource<T> whose underlying untyped data type UUID differs from T — typically from constructing the handle with mismatched generic parameters or mixed-up resources.","commonSituations":"Programmatic resource construction where the generic parameter drifted during refactor; wrapping an untyped resource produced by another loader; copying add_resource calls across resource kinds.","solutions":["Ensure the Resource<T> was created from data whose type UUID equals T's (construct via T's loader/constructor).","Print/inspect resource.untyped.type_uuid_non_blocking() before adding and use the matching typed call.","Fix generic parameters at the call site so T corresponds to the actual payload type.","Use the untyped add path (state.add_resource) if intentional mixed types must be stored."],"exampleFix":"// before\nlet res = Resource::<Texture>::new(ResourceData::from_model_data(data));\nrm.add_resource(&res)?; // payload is ModelData, handle says Texture\n// after\nlet res = Resource::<Model>::new(ResourceData::from_model_data(data));\nrm.add_resource(&res)?;","handlingStrategy":"validation","validationCode":"// before add_resource::<T>, confirm the payload type matches T\ndebug_assert_eq!(\n    resource.untyped.type_uuid_non_blocking(),\n    Some(<T as Reflect>::type_info().type_uuid)\n);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct Resource<T> only through T-specific constructors/loaders.","Avoid wildcard generic aliases that let T drift at call sites.","Unit-test add_resource calls with representative payloads.","Use distinct types (Texture, Model, SoundBuffer) instead of generic T in app code where possible."],"tags":["rust","panic","type-mismatch","resource-manager","generics"],"backgroundTag":"type-mismatch","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}