From 480c2bcb56edbc31cdc9cc188aa9cee2540a9b19 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Thu, 5 Sep 2024 09:55:06 -0400 Subject: [PATCH] Add note on `AssetServer::load` not being wasteful --- crates/bevy_asset/src/lib.rs | 4 +++- crates/bevy_asset/src/server/mod.rs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index ce4a6d858d..fe415071c1 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -18,7 +18,9 @@ //! //! The [`AssetServer`] is the main entry point for loading assets. //! Typically, you'll use the [`AssetServer::load`] method to load an asset from disk, which returns a [`Handle`]. -//! This handle will be used to instantiate various [`Component`](bevy_ecs::prelude::Component)s that require asset data to function, +//! Note that this method does not attempt to reload the asset if it has already been loaded: as long as the asset hasn't been dropped, +//! calling [`AssetServer::load`] on the same path will return the same handle. +//! The handle that's returned will be used to instantiate various [`Component`](bevy_ecs::prelude::Component)s that require asset data to function, //! which will then be spawned into the world as part of an entity. //! //! If we later want to manipulate this asset data (such as for displaying a death animation), we have three options: diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index a9e5fcddbf..1f73f951a8 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -266,6 +266,9 @@ 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. /// + /// Note that if the asset at this path is already loaded, this function will return the existing handle, + /// and will not waste work spawning a new load task. + /// /// 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: