FyroxEngine/Fyrox · error
Instantiating a model from a resource that is not loaded
Error message
Instantiating a model from a resource that is not loaded: {self:?} What it means
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.
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).
Example fix
// before
let model = rm.request::<ModelData>("enemy.fbx");
model.instantiate(&mut scene); // may not be loaded yet
// after
let model = rm.request::<ModelData>("enemy.fbx").await.unwrap();
model.instantiate(&mut scene); Defensive patterns
Strategy: try-catch
Validate before calling
// Check resource state before instantiating:
if model.state().is_ok() {
model.instantiate(&mut scene);
} else {
eprintln!("model not ready: {:?}", model.state());
} Type guard
fn is_loaded<T>(res: &Resource<T>) -> bool { matches!(res.state(), ResourceState::Ok(_)) } Try / catch
// Await the resource future before use; on failure log and skip instantiation
match rm.request::<ModelData>(path).await {
Ok(model) if model.state().is_ok() => model.instantiate(&mut scene),
other => eprintln!("skipping instantiation, resource not loaded: {other:?}"),
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Scene resource loading error
- Attempt to get reference to resource data while it is…
- Attempt to get reference to resource data while it is…
- Attempt to get reference to resource data which failed to…
- Unable to measure text due to unloaded fonts.
AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10).
Data as JSON: /api/errors/1eb5906013bcc5d6.
Report an issue: GitHub.
Appendix: source
Thrown at fyrox-impl/src/resource/model/mod.rs:505
let (root, old_to_new) = model_data.scene.graph.copy_node(
handle,
dest_graph,
false,
&mut |_, _| true,
pre_processing_callback,
&mut |_, original_handle, node| {
node.set_inheritance_data(original_handle, model.clone());
},
);
dest_graph.update_hierarchical_data_for_descendants(root);
(root, old_to_new)
}
fn begin_instantiation<'a>(&'a self, dest_scene: &'a mut Scene) -> InstantiationContext<'a> {
if !self.is_ok() {
Log::err(format!(
"Instantiating a model from a resource that is not loaded: {self:?}"
));
}
InstantiationContext {
model: self,
dest_scene,
local_transform: None,
ids: None,
}
}
fn instantiate(&self, dest_scene: &mut Scene) -> Handle<Node> {
self.begin_instantiation(dest_scene).finish()
}
fn instantiate_at(
&self,
scene: &mut Scene,View on GitHub (pinned to 76c91aad8e)