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

  1. Load the resource from a real file instead of memory so its kind is not Embedded, then serialize.
  2. Set/assign a path for the resource before serialization if your flow supports it.
  3. Exclude embedded resources from serialized data (remove or replace them with file-backed handles before saving).
  4. 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

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


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)