Skip to content

Commit

Permalink
Optional BEVY_ASSET_ROOT to find assets directory (#5346)
Browse files Browse the repository at this point in the history
# Objective

Fixes #5345

## Changelog

- Support optional env variable `BEVY_ASSET_ROOT` to explicitly specify root assets directory.
  • Loading branch information
Vrixyz committed Jan 16, 2023
1 parent a792f37 commit 8302899
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl AssetServer {
/// to look for loaders of `bar.baz` and `baz` assets.
///
/// By default the `ROOT` is the directory of the Application, but this can be overridden by
/// setting the `"CARGO_MANIFEST_DIR"` environment variable
/// setting the `"BEVY_ASSET_ROOT"` or `"CARGO_MANIFEST_DIR"` environment variable
/// (see <https://doc.rust-lang.org/cargo/reference/environment-variables.html>)
/// to another directory. When the application is run through Cargo, then
/// `"CARGO_MANIFEST_DIR"` is automatically set to the root folder of your crate (workspace).
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_asset/src/io/file_asset_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ impl FileAssetIo {
/// Returns the base path of the assets directory, which is normally the executable's parent
/// directory.
///
/// If the `CARGO_MANIFEST_DIR` environment variable is set, then its value will be used
/// If a `BEVY_ASSET_ROOT` environment variable is set, then its value will be used.
///
/// Else if the `CARGO_MANIFEST_DIR` environment variable is set, then its value will be used
/// instead. It's set by cargo when running with `cargo run`.
pub fn get_base_path() -> PathBuf {
if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
if let Ok(env_bevy_asset_root) = env::var("BEVY_ASSET_ROOT") {
PathBuf::from(env_bevy_asset_root)
} else if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
PathBuf::from(manifest_dir)
} else {
env::current_exe()
Expand Down

0 comments on commit 8302899

Please sign in to comment.