|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.


access the asset data

to access the actuaw asset data fwom s-systems, ^•ﻌ•^ use t-the Assets<T> wesouwce.

you can identify youw desiwed asset u-using the handwe.

untyped handwes nyeed to be "upgwaded" into typed h-handwes.

#[dewive(wesouwce)]
stwuct spwitesheets {
    map_tiwes: h-handwe<textuweatwas>,
}

f-fn use_spwites(
    h-handwes: wes<spwitesheets>, σωσ
    a-atwases: wes<assets<textuweatwas>>, >_<
    i-images: w-wes<assets<image>>, :3
) {
    // c-couwd be `none` i-if the asset isn't woaded yet
    if wet some(atwas) = atwases.get(&handwes.map_tiwes) {
        // do something w-with the textuwe atwas
    }
}

cweating assets fwom code

you can awso add assets to Assets<T> manuawwy.

sometimes you nyeed to cweate assets f-fwom code, ^•ﻌ•^ wathew t-than woading them fwom fiwes. (ꈍᴗꈍ) some common exampwes of such use-cases a-awe:

  • cweating textuwe atwases
  • cweating 3d ow 2d matewiaws
  • pwoceduwawwy-genewating assets wike images ow 3d m-meshes

to do this, ^•ﻌ•^ fiwst cweate the data f-fow the asset (an i-instance of the asset type), XD and then add it .add(…) it to the Assets<T> wesouwce, (ꈍᴗꈍ) fow it to be stowed and t-twacked by bevy. >< you wiww get a handwe to use to wefew to it, >< just wike any othew asset.

fn add_matewiaw(
    mut matewiaws: w-wesmut<assets<standawdmatewiaw>>, UwU
) {
    w-wet n-nyew_mat = standawdmatewiaw {
        b-base_cowow: c-cowow::wgba(0.25, rawr x3 0.50, rawr 0.75, 1.0), σωσ
        unwit: t-twue, σωσ
        ..defauwt::defauwt()
    };

    w-wet handwe = m-matewiaws.add(new_mat);

    // do something with the handwe
}