Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement of AssetServer::load documentation to help find a way to load from file with hash in filename #13272

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions crates/bevy_asset/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,38 @@ impl AssetServer {
/// it returns a "strong" [`Handle`]. When the [`Asset`] is loaded (and enters [`LoadState::Loaded`]), it will be added to the
/// associated [`Assets`] resource.
///
/// In case the file path contains a hashtag (`#`), the `path` must be specified using [`Path`]
/// or [`AssetPath`] because otherwise the hashtag would be interpreted as separator between
/// the file path and the label. For example:
///
/// ```no_run
/// # use bevy_asset::{AssetServer, Handle, LoadedUntypedAsset};
/// # use bevy_ecs::prelude::Res;
/// # use std::path::Path;
/// // `#path` is a label.
/// # fn setup(asset_server: Res<AssetServer>) {
/// # let handle: Handle<LoadedUntypedAsset> =
/// asset_server.load("some/file#path");
///
/// // `#path` is part of the file name.
/// # let handle: Handle<LoadedUntypedAsset> =
/// asset_server.load(Path::new("some/file#path"));
/// # }
/// ```
///
/// Furthermore, if you need to load a file with a hashtag in its name _and_ a label, you can
/// manually construct an [`AssetPath`].
///
/// ```no_run
/// # use bevy_asset::{AssetPath, AssetServer, Handle, LoadedUntypedAsset};
/// # use bevy_ecs::prelude::Res;
/// # use std::path::Path;
/// # fn setup(asset_server: Res<AssetServer>) {
/// # let handle: Handle<LoadedUntypedAsset> =
/// asset_server.load(AssetPath::from_path(Path::new("some/file#path")).with_label("subasset"));
/// # }
/// ```
///
/// You can check the asset's load state by reading [`AssetEvent`] events, calling [`AssetServer::load_state`], or checking
/// the [`Assets`] storage to see if the [`Asset`] exists yet.
///
Expand Down