mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
77309ba5d8
# Objective - Assets v2 does not currently offer a public API to load untyped assets ## Solution - Wrap the untyped handle in a `LoadedUntypedAsset` asset to offer a non-blocking load for untyped assets. The user does not need to know the actual asset type. - Handles to `LoadedUntypedAsset` have the same path as the wrapped asset, but their handles are shared using a label. The user side of `load_untyped` looks like this: ```rust use bevy::prelude::*; use bevy_internal::asset::LoadedUntypedAsset; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_systems(Update, check) .run(); } #[derive(Resource)] struct UntypedAsset { handle: Handle<LoadedUntypedAsset>, } fn setup( mut commands: Commands, asset_server: Res<AssetServer>, ) { let handle = asset_server.load_untyped("branding/banner.png"); commands.insert_resource(UntypedAsset { handle }); commands.spawn(Camera2dBundle::default()); } fn check( mut commands: Commands, res: Option<Res<UntypedAsset>>, assets: Res<Assets<LoadedUntypedAsset>>, ) { if let Some(untyped_asset) = res { if let Some(asset) = assets.get(&untyped_asset.handle) { commands.spawn(SpriteBundle { texture: asset.handle.clone().typed(), ..default() }); commands.remove_resource::<UntypedAsset>(); } } } ``` --- ## Changelog - `load_untyped` on the asset server now returns a handle to a `LoadedUntypedAsset` instead of an untyped handle to the asset at the given path. The untyped handle for the given path can be retrieved from the `LoadedUntypedAsset` once it is done loading. ## Migration Guide Whenever possible use the typed API in order to directly get a handle to your asset. If you do not know the type or need to use `load_untyped` for a different reason, Bevy 0.12 introduces an additional layer of indirection. The asset server will return a handle to a `LoadedUntypedAsset`, which will load in the background. Once it is loaded, the untyped handle to the asset file can be retrieved from the `LoadedUntypedAsset`s field `handle`. --------- Co-authored-by: Carter Anderson <mcanders1@gmail.com> |
||
---|---|---|
.. | ||
bevy_a11y | ||
bevy_animation | ||
bevy_app | ||
bevy_asset | ||
bevy_audio | ||
bevy_core | ||
bevy_core_pipeline | ||
bevy_derive | ||
bevy_diagnostic | ||
bevy_dylib | ||
bevy_dynamic_plugin | ||
bevy_ecs | ||
bevy_ecs_compile_fail_tests | ||
bevy_encase_derive | ||
bevy_gilrs | ||
bevy_gizmos | ||
bevy_gltf | ||
bevy_hierarchy | ||
bevy_input | ||
bevy_internal | ||
bevy_log | ||
bevy_macro_utils | ||
bevy_macros_compile_fail_tests | ||
bevy_math | ||
bevy_mikktspace | ||
bevy_pbr | ||
bevy_ptr | ||
bevy_reflect | ||
bevy_reflect_compile_fail_tests | ||
bevy_render | ||
bevy_scene | ||
bevy_sprite | ||
bevy_tasks | ||
bevy_text | ||
bevy_time | ||
bevy_transform | ||
bevy_ui | ||
bevy_utils | ||
bevy_window | ||
bevy_winit |