Skip to content

Commit 4583122

Browse files
committed
Document setting "CARGO_MANIFEST_DIR" for asset root (#1950)
This was nowhere documented inside Bevy. Should I also mention the use case of debugging a project? Closes #810 Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
1 parent e29a899 commit 4583122

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

crates/bevy_asset/src/asset_server.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ impl AssetServer {
212212
load_state
213213
}
214214

215+
/// Loads an Asset at the provided relative path.
216+
///
217+
/// The absolute Path to the asset is "ROOT/ASSET_FOLDER_NAME/path".
218+
///
219+
/// By default the ROOT is the directory of the Application, but this can be overridden by
220+
/// setting the `"CARGO_MANIFEST_DIR"` environment variable (see https://doc.rust-lang.org/cargo/reference/environment-variables.html)
221+
/// to another directory. When the application is run through Cargo, then
222+
/// `"CARGO_MANIFEST_DIR"` is automatically set to the root folder of your crate (workspace).
223+
///
224+
/// The name of the asset folder is set inside the
225+
/// [`AssetServerSettings`](crate::AssetServerSettings) resource. The default name is
226+
/// `"assets"`.
215227
pub fn load<'a, T: Asset, P: Into<AssetPath<'a>>>(&self, path: P) -> Handle<T> {
216228
self.load_untyped(path).typed()
217229
}

examples/asset/asset_loading.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ fn setup(
1515
meshes: Res<Assets<Mesh>>,
1616
mut materials: ResMut<Assets<StandardMaterial>>,
1717
) {
18-
// By default AssetServer will load assets from inside the "assets" folder
19-
// For example, the next line will load "assets/models/cube/cube.gltf#Mesh0/Primitive0"
18+
// By default AssetServer will load assets from inside the "assets" folder.
19+
// For example, the next line will load "ROOT/assets/models/cube/cube.gltf#Mesh0/Primitive0",
20+
// where "ROOT" is the directory of the Application.
21+
//
22+
// This can be overridden by setting the "CARGO_MANIFEST_DIR" environment variable (see
23+
// https://doc.rust-lang.org/cargo/reference/environment-variables.html)
24+
// to another directory. When the Application is run through Cargo, "CARGO_MANIFEST_DIR" is
25+
// automatically set to your crate (workspace) root directory.
2026
let cube_handle = asset_server.load("models/cube/cube.gltf#Mesh0/Primitive0");
2127
let sphere_handle = asset_server.load("models/sphere/sphere.gltf#Mesh0/Primitive0");
2228

0 commit comments

Comments
 (0)