{"record":{"id":"363ff6966c68c91f","repo":"FyroxEngine/Fyrox","slug":"embedded-resources-cannot-be-serialized","errorCode":null,"errorMessage":"Embedded resources cannot be serialized.","messagePattern":"Embedded resources cannot be serialized\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-resource/src/untyped.rs","lineNumber":268,"sourceCode":"/// ## Default state\n///\n/// Default state of every untyped resource is [`ResourceState::LoadError`] with a warning message,\n/// that the resource is in default state. This is a trade-off to prevent wrapping internals into\n/// `Option`, that in some cases could lead to convoluted code with lots of `unwrap`s and state\n/// assumptions.\n#[derive(Default, Clone, Reflect, Deserialize)]\n#[serde(from = \"Uuid\")]\n#[reflect(type_uuid = \"21613484-7145-4d1c-87d8-62fa767560ab\")]\npub struct UntypedResource(pub Arc<Mutex<ResourceHeader>>);\n\nimpl Serialize for UntypedResource {\n    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>\n    where\n        S: serde::Serializer,\n    {\n        let header = self.lock();\n        if header.kind == ResourceKind::Embedded {\n            panic!(\"Embedded resources cannot be serialized.\");\n        }\n        header.uuid.serialize(serializer)\n    }\n}\n\nimpl Visit for UntypedResource {\n    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {\n        let result = self.visit_with_type_uuid(name, None, visitor);\n        if let Err(err) = &result {\n            Log::err(format!(\"Resource error for untyped resource: {err}\"));\n            if let Ok(region) = visitor.enter_region(name) {\n                region.debug();\n            }\n            self.commit_error(PathBuf::default(), err.to_string());\n        }\n        result\n    }\n}","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-resource/src/untyped.rs#L250-L286","documentation":"UntypedResource's Serialize impl serializes only the resource's UUID. Embedded resources (created from in-memory data, ResourceKind::Embedded) have no stable file identity, so serializing them would produce a UUID that cannot be resolved later; the impl therefore panics.","triggerScenarios":"Serializing a scene/context containing a resource created from memory (ResourceManager::build_from_memory / embedded texture or model) with serde — e.g. serde_json::to_string(&resource) or saving a scene that references such a resource.","commonSituations":"Runtime-generated textures/models included in a scene being saved; saving editor scenes that contain screenshots or procedurally generated assets; tests serializing in-memory fixtures.","solutions":["Load the resource from a real file instead of memory so its kind is not Embedded, then serialize.","Set/assign a path for the resource before serialization if your flow supports it.","Exclude embedded resources from serialized data (remove or replace them with file-backed handles before saving).","Persist embedded resources yourself (write bytes to a file, register via loader) and reference that path."],"exampleFix":"// before\nlet texture = rm.build_from_memory(&bytes, Default::default())?; // Embedded\nserde_json::to_string(&texture)?; // panics\n// after\nlet texture = rm.request::<Texture>(\"data/foo.png\")?; // file-backed\nserde_json::to_string(&texture)?;","handlingStrategy":"validation","validationCode":"fn serializable(r: &UntypedResource) -> bool {\n    r.kind() != ResourceKind::Embedded\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Save only file-backed resources; dump embedded resources separately (e.g. write bytes to disk first).","Track which scene assets are runtime-generated.","Replace embedded handles with file-backed ones before scene save.","Document in editor tooling that embedded resources are not persistable via serde."],"tags":["rust","panic","serde","embedded-resources","serialization"],"backgroundTag":"unsupported-operation","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"}