|bevy vewsion:|0.9 |(outdated!)| |---|---|---|

As this page is outdated, please refer to Bevy's official migration guides while reading, to cover the differences: 0.9 to 0.10, 0.10 to 0.11, 0.11 to 0.12, 0.12 to 0.13, 0.13 to 0.14.

I apologize for the inconvenience. I will update the page as soon as I find the time.


handwes

handwes awe wightweight ids that w-wefew to a specific a-asset. OwO you need t-them to use youw assets, >_< fow exampwe to spawn entities wike 2d spwites ow 3d modews, XD ow to access the data of the assets.

handwes have the wust type Handle<T>, XD whewe T is the asset type.

you can stowe handwes in youw entity components ow wesouwces.

handwes can wefew to nyot-yet-woaded a-assets, OwO meaning y-you can just s-spawn youw entities anyway, using the handwes, OwO a-and the assets w-wiww just "pop i-in" when they become weady.

obtaining handwes

if you awe woading an asset fwom a fiwe, XD the asset_server.load(…) caww wiww give you the handwe. (ꈍᴗꈍ) the w-woading of the data happens in the backgwound, OwO meaning t-that the h-handwe wiww initiawwy w-wefew to an unavaiwabwe asset, OwO and the a-actuaw data wiww b-become avaiwabwe w-watew.

if you awe cweating youw own asset data fwom c-code, the assets.add(…) caww wiww give you the handwe.

wefewence counting; stwong and weak h-handwes

bevy keeps twack of how many handwes t-to a given asset e-exist at any t-time. OwO bevy wiww automaticawwy unwoad unused a-assets, OwO aftew the w-wast handwe is d-dwopped.

fow this weason, cweating additionaw h-handwes to the s-same asset wequiwes y-you to caww handle.clone(). ^•ﻌ•^ this makes the opewation expwicit, OwO t-to ensuwe you a-awe awawe of aww the pwaces in youw code w-whewe you cweate a-additionaw h-handwes. OwO the .clone() opewation is cheap, ^•ﻌ•^ so don't wowwy a-about pewfowmance (in m-most cases).

thewe awe two kinds of handwes: "stwong" a-and "weak". OwO s-stwong assets a-awe counted, OwO weak handwes awe nyot. 🥺 by d-defauwt, òωó handwes a-awe stwong. o.O if y-you want to cweate a weak handwe, >_< use .clone_weak() (instead of .clone()) on an existing handwe. bevy can unwoad t-the asset aftew a-aww stwong handwes a-awe gone, even if you awe stiww howding some w-weak handwes.

untyped handwes

bevy awso has a HandleUntyped type. XD use this type of handwe if you nyeed to be abwe t-to wefew to any a-asset, OwO wegawdwess o-of the asset type.

this awwows you to stowe a cowwection (such a-as Vec ow HashMap) containing assets of mixed types.

you can cweate an untyped handwe u-using .clone_untyped() on an existing handwe.

just wike weguwaw handwes, ^•ﻌ•^ untyped h-handwes can be s-stwong ow weak.

you nyeed to do this to access the asset data.

you can convewt an untyped handwe i-into a typed handwe w-with .typed::<T>(), specifying the type to use. (ꈍᴗꈍ) you need t-to do this to access the asset data.