bevyengine/bevy · error
Failed to find src_prefix {src_prefix:?} in {file_path:?}
Error message
Failed to find src_prefix {src_prefix:?} in {file_path:?} What it means
Panics in the embedded-asset helper _embedded_asset_path: while walking up the parents of the source file path, the expected src_prefix directory was never found. The macro-generated call could not relativize the invoking source file against the crate's src root, so the embedded asset's logical path cannot be computed.
Source
Thrown at crates/bevy_asset/src/io/embedded/mod.rs:268
/// - `asset_path`: path of the embedded asset relative to `file_path`
#[doc(hidden)]
pub fn _embedded_asset_path(
crate_name: &str,
src_prefix: &Path,
file_path: &Path,
asset_path: &Path,
) -> PathBuf {
let file_path = if cfg!(not(target_family = "windows")) {
// Work around bug: https://github.com/bevyengine/bevy/issues/14246
// Note, this will break any paths on Linux/Mac containing "\"
PathBuf::from(file_path.to_str().unwrap().replace("\\", "/"))
} else {
PathBuf::from(file_path)
};
let mut maybe_parent = file_path.parent();
let after_src = loop {
let Some(parent) = maybe_parent else {
panic!("Failed to find src_prefix {src_prefix:?} in {file_path:?}")
};
if parent.ends_with(src_prefix) {
break file_path.strip_prefix(parent).unwrap();
}
maybe_parent = parent.parent();
};
let asset_path = after_src.parent().unwrap().join(asset_path);
Path::new(crate_name).join(asset_path)
}
/// Creates a new `embedded` asset by embedding the bytes of the given path into the current binary
/// and registering those bytes with the `embedded` [`AssetSource`](crate::io::AssetSource).
///
/// This accepts the current [`App`] as the first parameter and a path `&str` (relative to the current file) as the second.
///
/// By default this will generate an [`AssetPath`] using the following rules:
///
/// 1. Search for the first `$crate_name/src/` in the path and trim to the path past that point.View on GitHub (pinned to 396ca72708)
Solutions
- Ensure the embedded_asset! invocation lives under the crate directory passed as src_prefix (normally the crate's src directory)
- Do not relocate or generate macro invocations from outside the crate source tree
- If invoking the helper manually, pass a src_prefix that is a real ancestor of file_path
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_asset/src/io/embedded/mod.rs:268 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/3b39e634ba90dd88.
Report an issue: GitHub.