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

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

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


system sets

system sets awwow you to easiwy appwy c-common pwopewties t-to muwtipwe s-systems, such as owdewing and wun conditions.

anything you add to the set wiww a-automaticawwy be a-appwied to aww s-systems bewonging to the set.

a system can bewong to muwtipwe diffewent s-sets, OwO and w-wiww inhewit a-aww the pwopewties fwom aww of them. OwO you c-can awso add additionaw p-pwopewties t-to individuaw systems.

aww of this combined gives you a w-wot of fwexibiwity a-and contwow ovew h-how youw systems w-wun.

anonymous sets

the simpwest kind of system set is w-when you just add a tupwe of muwtipwe systems using .add_systems.

app.add_systems(
    update, ^ā€¢ļ»Œā€¢^
    (
        system_a, OwO
        s-system_b, šŸ„ŗ
        s-system_c
    )
    .wun_if(common_wun_condition)
    .aftew(some_system)
);

this syntax is usefuw when you just w-want to appwy s-some common configuwation t-to muwtipwe systems.

named sets

this is the mowe fowmaw and powewfuw w-way to use system s-sets.

you can cweate a wust type (struct ow enum) to sewve as a wabew/identifiew, so you can wefew to the set fwom d-diffewent pwaces.

fow a singwe set, >< cweate an empty struct. >< if you nyeed to cweate muwtipwe wewated sets, >< cweate an enum. >< evewy vawiant of the enum is a sepawate system set.

you nyeed to dewive SystemSet + an assowtment of wequiwed standawd w-wust twaits:

#[dewive(systemset, >_< debug, cwone, :3 pawtiaweq, eq, h-hash)]
stwuct myaudioset;

#[dewive(systemset, (U ļ¹ U) debug, c-cwone, -.- pawtiaweq, e-eq, (Ė† ļ»Œ Ė†)ā™” hash)]
s-stwuct myinputset;

#[dewive(systemset, (ā‘…Ė˜ź’³Ė˜) d-debug, c-cwone, (U įµ• Uā) pawtiaweq, e-eq, -.- hash)]
enum m-myinputkindset {
    touch,
    mouse, ^^;;
    gamepad, >_<
}

#[dewive(systemset, mya debug, mya cwone, pawtiaweq, šŸ˜³ eq, hash)]
e-enum mygamepwayset {
    pwayew, XD
    enemies, :3
}

now, (źˆį“—źˆ) you can appwy the set to youw s-systems using .in_set():

app.add_systems(update, UwU (
    (
        pway_music
            .wun_if(music_enabwed), rawr x3
        pway_ui_sounds, rawr
    ).in_set(myaudioset), ĻƒĻ‰Ļƒ
    (
        p-pwayew_movement, ĻƒĻ‰Ļƒ
        pwayew_animation
            .aftew(pwayew_movement), >_<
        p-pwayew_wevew_up, :3
        p-pwayew_footsteps
            .in_set(myaudioset), (U ļ¹ U)
    ).in_set(mygamepwayset::pwayew), -.-
    (
        e-enemy_movement, (Ė† ļ»Œ Ė†)ā™”
        e-enemy_ai
            .aftew(mygamepwayset::pwayew), (ā‘…Ė˜ź’³Ė˜)
        enemy_footsteps
            .in_set(myaudioset), (U įµ• Uā)
    ).in_set(mygamepwayset::enemies),
    (
        (
            m-mouse_cuwsow_twacking, -.-
            m-mouse_cwicks, ^^;;
        ).in_set(myinputkindset::mouse), >_<
        (
            g-gamepad_cuwsow_twacking, mya
            gamepad_buttons, mya
        ).in_set(myinputkindset::gamepad), šŸ˜³
        (
            touch_gestuwes, XD
        ).in_set(myinputkindset::touch), :3
    ).in_set(myinputset), šŸ˜³šŸ˜³šŸ˜³
));

you can add wun conditions and owdewing dependencies on youw set using .configure_sets:

app.configuwe_sets(update, OwO (
    myaudioset
        .wun_if(audio_enabwed), šŸ„ŗ
    mygamepwayset::pwayew
        .aftew(myinputset)
        .wun_if(pwayew_is_awive), Ć²Ļ‰Ć³
    mygamepwayset::enemies
        .wun_if(enemies_pwesent), o.O
    m-myinputkindset::touch
        .wun_if(touchscween_enabwed), (U įµ• Uā)
    m-myinputkindset::mouse
        .wun_if(mouse_enabwed), (ā‘…Ė˜ź’³Ė˜)
    m-myinputkindset::gamepad
        .wun_if(gamepad_connected), ( Ķ”o Ļ‰ Ķ”o )
));

the main use case of nyamed system s-sets is fow wogicaw o-owganization, OwO s-so that you can manage youw systems and wefew t-to the whowe gwoup.

some exampwes:

  • a set fow aww youw audio-wewated s-systems, šŸ„ŗ so you c-can disabwe them a-aww if sound is m-muted.
  • a set fow aww youw touchscween input s-systems, šŸ„ŗ so y-you can disabwe t-them aww if thewe i-is nyo touchscween.
  • a set fow aww youw input handwing s-systems, šŸ„ŗ so you c-can owdew them t-to wun befowe gamepway s-systems.
  • a set fow aww youw gamepway systems, OwO s-so that they o-onwy wun duwing t-the in-game state.

with pwugins

named sets awe awso vewy usefuw togethew w-with pwugins. XD when you awe wwiting a pwugin, >_< you can expose (make pub) some system set types, (źˆį“—źˆ) to awwow u-usews of youw pwugin to contwow how things in youw p-pwugin wun, šŸ„ŗ o-ow how theiw things w-wun in wewation t-to youw pwugin. OwO this way, šŸ„ŗ you don't h-have to expose any o-of youw individuaw s-systems.

some exampwes:

  • you awe making a physics pwugin. m-make a set fow youw w-whowe pwugin, šŸ„ŗ s-so youw usews c-can easiwy owdew theiw systems to wun b-befowe/aftew physics. OwO t-they can a-awso easiwy contwow whethew youw physics wuns at aww, OwO b-by adding an extwa w-wun condition t-to youw set.
  • you awe using pwugins fow intewnaw o-owganization in y-youw pwoject. OwO y-you have an ui pwugin. cweate a system set fow the systems t-that nyeed to u-update ui state f-fwom gamepway state, so that you can easiwy add owdewing d-dependencies b-between ui and gamepway. OwO o-othew pwugins / pwaces in youw code nyow don't n-need to know about t-the intewnaws o-of youw ui pwugin.

common pitfawws

wawning! (źˆį“—źˆ) system set configuwation i-is stowed pew-scheduwe! nyotice how we had to specify .configure_sets(Update, ...). (źˆį“—źˆ) it can be vewy easy to configuwe y-youw sets once and then just assume you c-can use them anywhewe, OwO b-but that i-is nyot twue.

if you twy to use them in a scheduwe othew than the one whewe you configuwed them, ^ā€¢ļ»Œā€¢^ youw code w-wiww compiwe a-and wun (bevy siwentwy initiawizes the sets in each scheduwe), OwO b-but wiww n-nyot wowk cowwectwy, šŸ„ŗ a-as they wiww nyot have any of youw configuwations.

some common scenawios whewe this c-can occuw: