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.
This commit is contained in:
Thierry Berger 2023-01-16 17:36:09 +00:00
parent a792f37040
commit 83028994d1
2 changed files with 7 additions and 3 deletions

View file

@ -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).

View file

@ -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()