Skip to content

Commit 44c8cc6

Browse files
bugsweeperBD103
andauthored
Improvement of AssetServer::load documentation to help find a way to load from file with hash in filename (#13272)
# Objective - Fixes #13192 . - It is not possible to specify the path of the file and the subasset in it in one string slice, if there is a hash in the file name, because hash is separator between filename and subasset, so they must be separated explicitly ## Solution - Improved documentation for AssetServer::load. --------- Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
1 parent 21b3666 commit 44c8cc6

File tree

1 file changed

+32
-0
lines changed
  • crates/bevy_asset/src/server

1 file changed

+32
-0
lines changed

crates/bevy_asset/src/server/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,38 @@ impl AssetServer {
264264
/// it returns a "strong" [`Handle`]. When the [`Asset`] is loaded (and enters [`LoadState::Loaded`]), it will be added to the
265265
/// associated [`Assets`] resource.
266266
///
267+
/// In case the file path contains a hashtag (`#`), the `path` must be specified using [`Path`]
268+
/// or [`AssetPath`] because otherwise the hashtag would be interpreted as separator between
269+
/// the file path and the label. For example:
270+
///
271+
/// ```no_run
272+
/// # use bevy_asset::{AssetServer, Handle, LoadedUntypedAsset};
273+
/// # use bevy_ecs::prelude::Res;
274+
/// # use std::path::Path;
275+
/// // `#path` is a label.
276+
/// # fn setup(asset_server: Res<AssetServer>) {
277+
/// # let handle: Handle<LoadedUntypedAsset> =
278+
/// asset_server.load("some/file#path");
279+
///
280+
/// // `#path` is part of the file name.
281+
/// # let handle: Handle<LoadedUntypedAsset> =
282+
/// asset_server.load(Path::new("some/file#path"));
283+
/// # }
284+
/// ```
285+
///
286+
/// Furthermore, if you need to load a file with a hashtag in its name _and_ a label, you can
287+
/// manually construct an [`AssetPath`].
288+
///
289+
/// ```no_run
290+
/// # use bevy_asset::{AssetPath, AssetServer, Handle, LoadedUntypedAsset};
291+
/// # use bevy_ecs::prelude::Res;
292+
/// # use std::path::Path;
293+
/// # fn setup(asset_server: Res<AssetServer>) {
294+
/// # let handle: Handle<LoadedUntypedAsset> =
295+
/// asset_server.load(AssetPath::from_path(Path::new("some/file#path")).with_label("subasset"));
296+
/// # }
297+
/// ```
298+
///
267299
/// You can check the asset's load state by reading [`AssetEvent`] events, calling [`AssetServer::load_state`], or checking
268300
/// the [`Assets`] storage to see if the [`Asset`] exists yet.
269301
///

0 commit comments

Comments
 (0)