Asset Value Templates via asset_value() and HandleTemplate::Value#23839
Asset Value Templates via asset_value() and HandleTemplate::Value#23839alice-i-cecile merged 3 commits intobevyengine:mainfrom
asset_value() and HandleTemplate::Value#23839Conversation
1f09306 to
15cdea8
Compare
|
Keep in mind our AssetServer is also a Mutex, so this would be equivalent to a load I think? Which is like.... Not a big deal IMO? Or if it is we have bigger problems lol. In fact, this should be even faster since the asset server is likely under more contention than each asset template. |
The difference here is that in an ideal world, we hit the asset server once to retrieve the handle, then clone that directly rather than asking the asset server again. A non-BSN equivalent would be much faster, as it could just cache the handle somewhere. These are only on par when you spawn something exactly once. |
15cdea8 to
06a5fba
Compare
| app.world_mut().spawn_scene(ui_loaded_asset()).unwrap(); | ||
| }); | ||
|
|
||
| drop(handle); |
There was a problem hiding this comment.
Nit: this drop does nothing.

Objective
Temporary simple / suboptimal solution to #23822
It would be very nice to be able to define assets inline in BSN.
Solution
HandleTemplate::Valuevariant, which contains anArc<Mutex<AssetOrHandle<T>>>Arc<Mutex<HandleOrTemplate>and return the handle. Future calls will lock the mutex and return the cached handle.asset_value(SOME_ASSET)function to improve ergonomics.3d_sceneto illustrateDoing a lock on every spawn is obviously suboptimal. The long term plan for "inline assets in BSN" is defined in #23822 and will not use this locking approach.