FyroxEngine/Fyrox · error
Embedded resources cannot be serialized.
Error message
Embedded resources cannot be serialized.
What it means
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.
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.
Example fix
// before
let texture = rm.build_from_memory(&bytes, Default::default())?; // Embedded
serde_json::to_string(&texture)?; // panics
// after
let texture = rm.request::<Texture>("data/foo.png")?; // file-backed
serde_json::to_string(&texture)?; Defensive patterns
Strategy: validation
Validate before calling
fn serializable(r: &UntypedResource) -> bool {
r.kind() != ResourceKind::Embedded
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Registering empty path.
- Animation pool must be empty on load!
- Graph pool must be empty on load!
- Height data type error
- Texture is not rectangle
AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10).
Data as JSON: /api/errors/363ff6966c68c91f.
Report an issue: GitHub.
Appendix: source
Thrown at fyrox-resource/src/untyped.rs:268
/// ## Default state
///
/// Default state of every untyped resource is [`ResourceState::LoadError`] with a warning message,
/// that the resource is in default state. This is a trade-off to prevent wrapping internals into
/// `Option`, that in some cases could lead to convoluted code with lots of `unwrap`s and state
/// assumptions.
#[derive(Default, Clone, Reflect, Deserialize)]
#[serde(from = "Uuid")]
#[reflect(type_uuid = "21613484-7145-4d1c-87d8-62fa767560ab")]
pub struct UntypedResource(pub Arc<Mutex<ResourceHeader>>);
impl Serialize for UntypedResource {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let header = self.lock();
if header.kind == ResourceKind::Embedded {
panic!("Embedded resources cannot be serialized.");
}
header.uuid.serialize(serializer)
}
}
impl Visit for UntypedResource {
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
let result = self.visit_with_type_uuid(name, None, visitor);
if let Err(err) = &result {
Log::err(format!("Resource error for untyped resource: {err}"));
if let Ok(region) = visitor.enter_region(name) {
region.debug();
}
self.commit_error(PathBuf::default(), err.to_string());
}
result
}
}View on GitHub (pinned to 76c91aad8e)