From 83028994d17842e975b17bd849ab76c3ef6e5fbb Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Mon, 16 Jan 2023 17:36:09 +0000 Subject: [PATCH] Optional BEVY_ASSET_ROOT to find assets directory (#5346) # Objective Fixes #5345 ## Changelog - Support optional env variable `BEVY_ASSET_ROOT` to explicitly specify root assets directory. --- crates/bevy_asset/src/asset_server.rs | 2 +- crates/bevy_asset/src/io/file_asset_io.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index abb13ccad2..41c91fe7c7 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -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 ) /// 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). diff --git a/crates/bevy_asset/src/io/file_asset_io.rs b/crates/bevy_asset/src/io/file_asset_io.rs index 59447dfac5..e4f9a57bba 100644 --- a/crates/bevy_asset/src/io/file_asset_io.rs +++ b/crates/bevy_asset/src/io/file_asset_io.rs @@ -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()