{"record":{"id":"1eb5906013bcc5d6","repo":"FyroxEngine/Fyrox","slug":"instantiating-a-model-from-a-resource-that-is-not","errorCode":null,"errorMessage":"Instantiating a model from a resource that is not loaded: {self:?}","messagePattern":"Instantiating a model from a resource that is not loaded: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-impl/src/resource/model/mod.rs","lineNumber":505,"sourceCode":"        let (root, old_to_new) = model_data.scene.graph.copy_node(\n            handle,\n            dest_graph,\n            false,\n            &mut |_, _| true,\n            pre_processing_callback,\n            &mut |_, original_handle, node| {\n                node.set_inheritance_data(original_handle, model.clone());\n            },\n        );\n\n        dest_graph.update_hierarchical_data_for_descendants(root);\n\n        (root, old_to_new)\n    }\n\n    fn begin_instantiation<'a>(&'a self, dest_scene: &'a mut Scene) -> InstantiationContext<'a> {\n        if !self.is_ok() {\n            Log::err(format!(\n                \"Instantiating a model from a resource that is not loaded: {self:?}\"\n            ));\n        }\n        InstantiationContext {\n            model: self,\n            dest_scene,\n            local_transform: None,\n            ids: None,\n        }\n    }\n\n    fn instantiate(&self, dest_scene: &mut Scene) -> Handle<Node> {\n        self.begin_instantiation(dest_scene).finish()\n    }\n\n    fn instantiate_at(\n        &self,\n        scene: &mut Scene,","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/resource/model/mod.rs#L487-L523","documentation":"ModelResource::begin_instantiation checks that the model resource is in Ok (loaded) state before instantiating into a scene. If the resource is still pending or failed to load, instantiation proceeds with invalid data, so the engine logs this error including the resource state for diagnosis.","triggerScenarios":"Calling instantiate, instantiate_at, or instantiate_and_attach on a ModelResource whose loading has not completed (or failed) — typically instantiating in the same frame the resource was requested via ResourceManager::request rather than awaiting load.","commonSituations":"Spawning a prefab immediately after calling request() without awaiting the future; referencing a model path that failed to load; blocking-free async game loops that consume resources before they resolve.","solutions":["Await resource loading before instantiation: use resource.acquire() awaited or `let model = rm.request::<Model>(path).await.unwrap();`.","Switch from request() to ResourceManager::try_request + state polling, or use the async .load pattern, before calling instantiate.","Verify the model path resolves to an existing, valid resource (check ResourceManager logs for prior load errors)."],"exampleFix":"// before\nlet model = rm.request::<ModelData>(\"enemy.fbx\");\nmodel.instantiate(&mut scene); // may not be loaded yet\n\n// after\nlet model = rm.request::<ModelData>(\"enemy.fbx\").await.unwrap();\nmodel.instantiate(&mut scene);","handlingStrategy":"try-catch","validationCode":"// Check resource state before instantiating:\nif model.state().is_ok() {\n    model.instantiate(&mut scene);\n} else {\n    eprintln!(\"model not ready: {:?}\", model.state());\n}","typeGuard":"fn is_loaded<T>(res: &Resource<T>) -> bool { matches!(res.state(), ResourceState::Ok(_)) }","tryCatchPattern":"// Await the resource future before use; on failure log and skip instantiation\nmatch rm.request::<ModelData>(path).await {\n    Ok(model) if model.state().is_ok() => model.instantiate(&mut scene),\n    other => eprintln!(\"skipping instantiation, resource not loaded: {other:?}\"),\n}","preventionTips":["Always await resource load futures before instantiation.","Preload all prefabs during a loading screen rather than lazily in gameplay code.","Check ResourceManager logs for failed loads at startup."],"tags":["resource-loading","async","prefab","scene"],"backgroundTag":"resource-not-found","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"}