pub struct LoadBuilder<'a> { /* private fields */ }Expand description
A builder for initiating a more complex load than the one provided by AssetServer::load.
For example, a load may look like:
asset_server
.load_builder()
.with_settings(settings)
.override_unapproved()
.load("my.path")Implementations§
Source§impl<'a> LoadBuilder<'a>
impl<'a> LoadBuilder<'a>
Sourcepub fn with_settings<S: Settings>(
self,
settings: impl Fn(&mut S) + Send + Sync + 'static,
) -> Self
pub fn with_settings<S: Settings>( self, settings: impl Fn(&mut S) + Send + Sync + 'static, ) -> Self
Use the given settings function to override the asset’s AssetLoader settings.
The type S must match the configured AssetLoader::Settings or settings changes will
be ignored and an error will be printed to the log.
Repeatedly calling this method will “chain” the operations (matching the order of these calls).
Sourcepub fn override_unapproved(self) -> Self
pub fn override_unapproved(self) -> Self
Loads from unapproved paths are allowed, even if
AssetPlugin::unapproved_path_mode is
Deny.
Sourcepub fn with_guard(self, guard: impl Send + Sync + 'static) -> Self
pub fn with_guard(self, guard: impl Send + Sync + 'static) -> Self
Sets the guard item that is held during the load.
The guard item is dropped when either the asset is loaded or loading has failed. This allows
the Drop implementation of the guard item to notify the caller in some way. See the
multi_asset_sync example for usage.
Only the last guard is kept. The previous guards are dropped before the load begins.
Sourcepub fn load<'b, A: Asset>(
self,
asset_path: impl Into<AssetPath<'b>>,
) -> Handle<A>
pub fn load<'b, A: Asset>( self, asset_path: impl Into<AssetPath<'b>>, ) -> Handle<A>
Begins loading an Asset of type A stored at path. This will not block on the asset load. Instead,
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.
This matches the behavior of AssetServer::load, but supporting all other features of the
builder. See its docs for more details.
Sourcepub fn load_erased<'b>(
self,
type_id: TypeId,
asset_path: impl Into<AssetPath<'b>>,
) -> UntypedHandle
pub fn load_erased<'b>( self, type_id: TypeId, asset_path: impl Into<AssetPath<'b>>, ) -> UntypedHandle
Same as load, but the type of the asset to load is specified by the runtime
type_id.
Sourcepub fn load_untyped<'b>(
self,
asset_path: impl Into<AssetPath<'b>>,
) -> Handle<LoadedUntypedAsset>
pub fn load_untyped<'b>( self, asset_path: impl Into<AssetPath<'b>>, ) -> Handle<LoadedUntypedAsset>
Load an asset without knowing its type. The method returns a handle to a LoadedUntypedAsset.
Once the LoadedUntypedAsset is loaded, an untyped handle for the requested path can be
retrieved from it.
use bevy_asset::{Assets, Handle, LoadedUntypedAsset};
use bevy_ecs::system::Res;
use bevy_ecs::resource::Resource;
#[derive(Resource)]
struct LoadingUntypedHandle(Handle<LoadedUntypedAsset>);
fn resolve_loaded_untyped_handle(loading_handle: Res<LoadingUntypedHandle>, loaded_untyped_assets: Res<Assets<LoadedUntypedAsset>>) {
if let Some(loaded_untyped_asset) = loaded_untyped_assets.get(&loading_handle.0) {
let handle = loaded_untyped_asset.handle.clone();
// continue working with `handle` which points to the asset at the originally requested path
}
}This indirection enables a non blocking load of an untyped asset, since I/O is required to figure out the asset type before a handle can be created.
Sourcepub async fn load_untyped_async<'b>(
self,
asset_path: impl Into<AssetPath<'b>>,
) -> Result<UntypedHandle, AssetLoadError>
pub async fn load_untyped_async<'b>( self, asset_path: impl Into<AssetPath<'b>>, ) -> Result<UntypedHandle, AssetLoadError>
Asynchronously load an asset that you do not know the type of statically. If you do know the type of the asset,
you should use AssetServer::load. If you don’t know the type of the asset, but you can’t use an async method,
consider using AssetServer::load_untyped.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for LoadBuilder<'a>
impl<'a> !UnwindSafe for LoadBuilder<'a>
impl<'a> Freeze for LoadBuilder<'a>
impl<'a> Send for LoadBuilder<'a>
impl<'a> Sync for LoadBuilder<'a>
impl<'a> Unpin for LoadBuilder<'a>
impl<'a> UnsafeUnpin for LoadBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.