Skip to content

Commit

Permalink
Add load_untyped to LoadContext (#10526)
Browse files Browse the repository at this point in the history
# Objective

Give us the ability to load untyped assets in AssetLoaders.

## Solution

Basically just copied the code from `load`, but used
`asset_server.load_untyped` instead internally.

## Changelog

Added `load_untyped` method to `LoadContext`
  • Loading branch information
Testare authored and cart committed Nov 30, 2023
1 parent 520a09a commit ce69959
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
Settings,
},
path::AssetPath,
Asset, AssetLoadError, AssetServer, AssetServerMode, Assets, Handle, UntypedAssetId,
UntypedHandle,
Asset, AssetLoadError, AssetServer, AssetServerMode, Assets, Handle, LoadedUntypedAsset,
UntypedAssetId, UntypedHandle,
};
use bevy_ecs::world::World;
use bevy_utils::{BoxedFuture, CowArc, HashMap, HashSet};
Expand Down Expand Up @@ -462,6 +462,21 @@ impl<'a> LoadContext<'a> {
handle
}

/// Retrieves a handle for the asset at the given path and adds that path as a dependency of the asset without knowing its type.
pub fn load_untyped<'b>(
&mut self,
path: impl Into<AssetPath<'b>>,
) -> Handle<LoadedUntypedAsset> {
let path = path.into().to_owned();
let handle = if self.should_load_dependencies {
self.asset_server.load_untyped(path)
} else {
self.asset_server.get_or_create_path_handle(path, None)
};
self.dependencies.insert(handle.id().untyped());
handle
}

/// Loads the [`Asset`] of type `A` at the given `path` with the given [`AssetLoader::Settings`] settings `S`. This is a "deferred"
/// load. If the settings type `S` does not match the settings expected by `A`'s asset loader, an error will be printed to the log
/// and the asset load will fail.
Expand Down

0 comments on commit ce69959

Please sign in to comment.