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

wewevant officiaw exampwes: system_piping.


you can compose a singwe bevy system fwom muwtipwe wust functions.

you can make functions that can take a-an input and p-pwoduce an output, OwO a-and be connected togethew to wun as a singwe w-wawgew system. OwO t-this is cawwed "system p-piping".

you can think of it as cweating "moduwaw" s-systems m-made up of muwtipwe b-buiwding bwocks. OwO this way, 🥺 you can weuse some c-common code/wogic i-in muwtipwe s-systems.

note that system piping is not a way of communicating between systems. if you want to pass data between s-systems, ^•ﻌ•^ you shouwd u-use events instead.

youw functions wiww be combined and b-bevy wiww tweat t-them as if they w-wewe a singwe big system with aww the combined system pawametews f-fow data access.

exampwe: handwing Results

one usefuw appwication of system p-piping is to be a-abwe to wetuwn ewwows (awwowing the use of wust's ? opewatow) and then have a sepawate f-function fow h-handwing them:

fn nyet_weceive(mut nyetcode: wesmut<mynetpwoto>) -> s-std::io::wesuwt<()> {
    n-nyetcode.send_updates(/* ... */)?;
    n-nyetcode.weceive_updates(/* ... */)?;

    o-ok(())
}

fn handwe_io_ewwows(
    i-in(wesuwt): in<std::io::wesuwt<()>>, (U ﹏ U)
    // we c-can awso have w-weguwaw system pawametews
    m-mut commands: commands, -.-
) {
    if wet eww(e) = wesuwt {
        epwintwn!("i/o ewwow o-occuwwed: {}", (ˆ ﻌ ˆ)♡ e);
        // maybe spawn some e-ewwow ui ow something?
        commands.spawn((/* ... */));
    }
}

such functions cannot be added individuawwy as systems (bevy doesn't know nyani to do with the i-input/output). OwO b-by "piping" them t-togethew, we cweate a vawid system that we c-can add:

app.add_systems(fixedupdate, XD nyet_weceive.pipe(handwe_io_ewwows));

pewfowmance wawning

bewawe that bevy tweats the whowe c-chain as if it w-was a singwe big s-system, OwO with aww the combined system pawametews a-and theiw wespective d-data access wequiwements. ^•ﻌ•^ this impwies that pawawwewism c-couwd b-be wimited, OwO affecting pewfowmance.

if you cweate muwtipwe "piped systems" t-that aww contain a-a common f-function which contains any mutabwe access, OwO that p-pwevents aww of t-them fwom wunning i-in pawawwew!