Concise Reference Book for the Bevy Game Engine

Overview

Unofficial Bevy Cheat Book

Click here to read the book!

Concise reference to programming in the Bevy game engine.

Covers useful syntax, features, programming patterns, and solutions ("recipes") for common game development tasks.

Designed to be easy to read, straight to the point, using simple language to focus on the important information.

License

All code in the book is under CC0 (public domain). To the extent possible under law, the relevant Authors have waived all copyright and related or neighboring rights to Bevy Cheatbook Example Code.

The text of the book is under CC BY-NC-SA 4.0. Copyright © 2021 Jasen Borisov.

Contributions Welcome!

See the Contributing page of the book for advice!

Help Wanted

Specific things that I would really appreciate help with:

Comments
  • Major Overhaul for the Bevy 0.5 Release

    Major Overhaul for the Bevy 0.5 Release

    Creating this PR as a place for any feedback and review, if anyone from the community has any comments about the new version of the book that I am working on for the new Bevy 0.5 release.

    Click here to read the rendered version of the new book.

    The new version has major changes and significant reorganization. Many pages have been partly or entirely rewritten. I have tried my best to address any confusion that I noticed people in Discord running into, and to generally make the book a better introductory experience for people new to bevy.

    If you have the time, I would really appreciate it if you could try to put yourself in the shoes of a bevy beginner and try to "learn from the book" (by reading the chapters/pages on introductory topics, etc.), and provide feedback on what that feels like.


    New chapter structure:

    • "Bevy Basics" has been replaced with "Bevy Programming" and "Bevy Features".
      • "Bevy Programming" teaches how to program with bevy. (features of bevy as a framework and its mental model) It is further split into "Basics" and "Advanced".
      • "Bevy Features" covers how to use core game engine features of bevy.
    • "Advanced Patterns" is more explicit about covering more controversial techniques for advanced users.
    • "Bevy on Different Platforms": new chapter to address non-desktop platforms; the WASM content from #23 will eventually be incorporated under here.

    Introductory pages on the basics of ECS have been expanded with extra text, to help teach users unfamiliar with the ECS paradigm. Most other things have also been expanded with more detail to help teach new users.

    "Bevy Programming" pages have been revised to make explanations clearer and to better recommend good practices. I've tried to limit such recommendations to common confusions about the ECS paradigm, because I believe that these introductory chapters should be as unopinionated as possible.

    Entirely new pages:

    • Bevy Programming > Intro to ECS
    • Bevy Programming > System Ordering
    • Bevy Programming > System Sets
    • Bevy Programming > Run Criteria
    • Bevy Programming > Labels
    • Bevy Features > Transforms and Coordinates
    • Common Pitfalls > UI is not displaying
    • Bevy on Different Platforms

    Pages with major rewrites or new content:

    • Bevy Programming > Resources > Usage Advice
    • Bevy Programming > Plugins
    • Bevy Programming > Local Resources
    • Bevy Programming > Hierarchical Entities
    • Bevy Programming > States
    • Bevy Programming > Stages
    • Bevy Features > Assets

    Addressed Issues:

    • Closes #28
    • Closes #20
    • Closes #5
    • Closes #37
    • Closes #31
    • Closes #4
    • Closes #3
    • ~~not #2~~
    • Closes #40
    • Closes #41
    • Closes #45

    Meta organizational changes:

    • The main book will no longer contain any info specific to bevy's git main branch. Instead, the next branch is the place for any work to cover new developments, in preparation for the next bevy release. It will stay published at the URL above.
    opened by inodentry 10
  • Add note that dynamic linking is unsupported on WASM

    Add note that dynamic linking is unsupported on WASM

    I'm not sure how to debug from here, looking for ideas.

    % cargo -vv run --target wasm32-unknown-unknown
    
    error: cannot produce dylib for `bevy_dylib v0.6.0` as the target `wasm32-unknown-unknown` does not support these crate types
    
    % cat .cargo/config.toml 
    [target.wasm32-unknown-unknown]
    runner = "wasm-server-runner"
    
    C-bug-misleading V-current S-platforms P-web Z-small 
    opened by chmorgan 7
  • Debugging failed IntoSystem macro

    Debugging failed IntoSystem macro

    Stopgap solution for: https://github.com/bevyengine/bevy/issues/1519

    IMO, the correct choice here is to have a page for "I can't add my function as a system!" or something of the like. It should explain each of the options that impl SystemParam, and call out common mistakes for each. As an example, missing &mut for Commands, missing & for components etc.

    opened by alice-i-cecile 7
  • Broken link on second place in serp

    Broken link on second place in serp

    Hi there ✌️

    I'm a web developer landing in the Rust's and Bevy's communities.

    I don't know if what I'll report is even possible to fix due to that fact that the Rusts books seem to be self-generated but I've searched for "bevy queries" on Google and found a broken link at the second place of the serp, linking to this page:

    https://bevy-cheatbook.github.io/cheatsheet/release.html

    I have a huge background into web development (10y+) so ask me if my skills can help :)

    S-meta 
    opened by RomainMazB 5
  • Page about working with GLTF in Bevy

    Page about working with GLTF in Bevy

    Add a section describing how to work with asset labels to address sub-assets in GLTF files.

    It should cover how to get individual meshes, scenes, textures, etc. that were loaded from a GLTF file.

    It should cover both bevy-generated labels (Scene0, Primitive0, ...) and custom labels (when a GLTF file was exported with labels included in the file).

    C-enhancement S-cookbook 
    opened by inodentry 5
  • Fix assets-ready.rs example

    Fix assets-ready.rs example

    The example doesn't initialize the AssetsLoading resource, causing:

    'Requested resource does not exist: playground::AssetsLoading', /path/to/system_param.rs:394:17
    

    This type of change should likely be added to the other examples.

    The change respects the current structure of not showing the strictly necessary code (ie. no Default attribute, and no main() function).

    opened by 64kramsystem 4
  • WASM chapter

    WASM chapter

    First of all, a big thank you for providing this cheatbook. It has helped me learn Bevy faster than I otherwise would have. With this I hope to contribute back a little in a problem space that I've done a lot of digging in by myself.

    I am by no means an expert regarding WebAssembly, however. Therefore, I'd really appreciate if some others could chime in here and offer corrections or additions. I did test everything and do apply the majority of practices documented here in my own projects, but mistakes can always happen.

    Additionally, as per the maintainer's request, I hereby waive all copyright regarding my entire contribution.

    opened by zaszi 4
  • Labels chapter: Add missing required PartialEq trait

    Labels chapter: Add missing required PartialEq trait

    PartialEq is a required trait for labels, and it's missing in the description. It's a minor correction, but it's a confusing to have the description not matching the examples 🙂

    Thanks for your work 🙂

    opened by 64kramsystem 3
  • set_window_icon recipe freezes the bevy app on windows

    set_window_icon recipe freezes the bevy app on windows

    I followed https://bevy-cheatbook.github.io/cookbook/window-icon.html, but that seems to freeze the bevy app. Not sure if it's a bug in winit or bevy or how it's used in the example.

    It's specifically the line

    primary.set_window_icon(Some(icon));
    

    That seems to make everything freeze

    C-bug-code S-cookbook V-current P-windows 0- high priority Z-small 
    opened by johanhelsing 3
  • handle orthographic scale in cursor2world

    handle orthographic scale in cursor2world

    this currently doesn't work correctly when an orthographic scale is applied. this pr fixes it by setting the w component of the pos_wld vector to 1. / ortho_scale, undoing the scale before multiplying the input vector by the view matrix.

    opened by hazelsparrow 3
  • Document pitfalls around using generic system parameters

    Document pitfalls around using generic system parameters

    The immediately obvious method to build systems generic over a system param such as

    fn generic_system<P: SystemParam>(param: P) {}
    

    doesn't work. This is because system parameters need to be generic over two lifetimes so bevy can call it with the correct lifetimes, whereas directly using a given generic as a parameter locks it into a single type that doesn't match what bevy can give it. The solution is to "add back" the lifetimes by going through traits, such as

    fn generic_system<P: SystemParam>(
        param: <P::Fetch as SystemParamFetch<'_, '_>>::Item,
    ) {}
    

    Notes: usually a generic system can't do much with it's generic parameter and needs to hand it over to a user-provided function. If this is implemented as one function, this can require extra bounds:

    fn generic_system_builder<P, F>(func: F) -> BoxedSystem
    where
        F: Send + Sync + 'static,
        F: Fn(<P::Fetch as SystemParamFetch<'_, '_>>::Item),
        for<'w, 's> <P::Fetch as SystemParamFetch<'w, 's>>::Item: SystemParam<Fetch = P::Fetch>,
        P: SystemParam,
    {
        let f = move |x: Res<i32>, p: <P::Fetch as SystemParamFetch<'_, '_>>::Item| {
            dbg!(x);
            func(p);
        };
        Box::new(f.system())
    }
    

    Removing any of the where bounds here will cause a compile error. As for potential issues on the callsite for such a function, the parameters need to be given to the builder and cannot be inferred from the closure parameters.

    // compiles
    generic_system_builder::<Res<u32>, _>(|x| {});
    // doesn't compile
    generic_system_builder(|x: Res<u32>| {});
    

    Similar patterns also used in the new renderer, with traits such as RenderCommand: https://github.com/bevyengine/bevy/blob/f5039a476d48ec19bd74c94e83e10772565c68f1/crates/bevy_render/src/render_phase/draw.rs#L132

    bevy::ecs::system has useful type aliases for working with this pattern, such as lifetimeless versions of Res, Query, etc. and aliases for long type paths.

    In the future, when rust stabilizes GAT s, all this should become significantly simpler

    C-enhancement C-bug-misleading S-programming V-current Z-medium S-patterns 
    opened by TheRawMeatball 3
  • Fix warning in pan-orbit-camera

    Fix warning in pan-orbit-camera

    Getting the warning below in Bevy 0.9

    2023-01-05T22:50:16.707312Z  WARN bevy_ecs::event: Missed 213 `bevy_input::mouse::MouseMotion` events. Consider reading from the `EventReader` more often (generally the best solution) or calling Events::update() less frequently (normally this is called once per frame). This problem is most likely due to run criteria/fixed timesteps or consuming events conditionally. See the Events documentation for more information. 
    

    Doing what is recommended

    opened by enbugger 0
  • page about SystemParam derive syntax

    page about SystemParam derive syntax

    #[derive(SystemParam)]
    struct CustomParam<'w, 's> {
        res: Res<'w, AssetServer>,
        query: Query<'w, 's, Read<Transform>>,
        local: Local<'s, i32>,
    }
    
    C-enhancement S-programming V-current 0- high priority Z-medium 
    opened by inodentry 0
  • Advice on specifying the branch of libraries via git is wrong

    Advice on specifying the branch of libraries via git is wrong

    On this page, the following line is provided:

    # add any 3rd-party plugins you use, and make sure to use the correct branch
    # (alternatively, you could also specify a commit hash, with "rev")
    bevy_thing = { git = "https://github.com/author/bevy_thing?branch=bevy_main" }
    

    This is wrong: the ?branch part of the URL is simply ignored, and the main branch is used. Instead, you must specify `branch = "bevy_main".

    C-bug-code C-bug-misleading S-setup V-current Z-small 
    opened by alice-i-cecile 0
  • "Logging, console messages" section should mention what plugin you need in order for logging to work

    If you're not using DefaultPlugins, what plugin do you need for logging to work? I think it's the LogPlugin, but I'm not sure.

    I went to the bevy cheatbook page, but couldn't find any info on this.

    C-enhancement S-features V-current Z-small 
    opened by bzm3r 0
  • Quick math reference page

    Quick math reference page

    Show all the common methods for working with angles, vecs, matrices, etc:

    • convert f32 to vec*: splat
    • add dimension (vec2 -> vec3): extend
    • remove dimension (vec3 -> vec2): truncate
    • convert degrees/radians
    • ...
    C-enhancement S-misc V-current Z-large 1- needs research 
    opened by inodentry 0
Owner
null
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Sélène Amanita 11 May 28, 2023
2d Endless Runner Game made with Bevy Game Engine

Cute-runner A 2d Endless Runner Game made with Bevy Game Engine. Table of contents Project Infos Usage Screenshots Disclaimer Project Infos Date: Sept

JoaoMarinho 2 Jul 15, 2022
A game of snake written in Rust using the Bevy game engine, targeting WebGL2

Snake using the Bevy Game Engine Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.toml (loca

Michael Dorst 0 Dec 26, 2021
A game made in one week for the Bevy engine's first game jam

¿Quien es el MechaBurro? An entry for the first Bevy game jam following the theme of "Unfair Advantage." It was made in one week using the wonderful B

mike 20 Dec 23, 2022
A Client/Server game networking plugin using QUIC, for the Bevy game engine.

Bevy Quinnet A Client/Server game networking plugin using QUIC, for the Bevy game engine. Bevy Quinnet QUIC as a game networking protocol Features Roa

Gilles Henaux 65 Feb 20, 2023
Simple retro game made using Rust bracket-lib by following "Herbert Wolverson's Hands on Rust" book.

Flappy Dragon Code from This program is a result of a tutorial i followed from Herbert Wolverson's Hands-on Rust Effective Learning through 2D Game De

Praneeth Chinthaka Ranasinghe 1 Feb 7, 2022
Basic first-person fly camera for the Bevy game engine

bevy_flycam A basic first-person fly camera for Bevy 0.4 Controls WASD to move horizontally SPACE to ascend LSHIFT to descend ESC to grab/release curs

Spencer Burris 85 Dec 23, 2022
Inspector plugin for the bevy game engine

bevy-inspector-egui This crate provides the ability to annotate structs with a #[derive(Inspectable)], which opens a debug interface using egui where

Jakob Hellermann 517 Dec 31, 2022
Crossterm plugin for the bevy game engine

What is bevy_crossterm? bevy_crossterm is a Bevy plugin that uses crossterm as a renderer. It provides custom components and events which allow users

null 79 Nov 2, 2022
Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions

Introduction Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions. (hand interaction with boxes missing

Mika 52 Nov 14, 2022
A physics lib for the bevy game engine based on physme

physimple Physimple aims to be the simplest(and capable) physics engine(currently for bevy) WARNING Beware for breaking changes with each update for n

null 24 Oct 28, 2022
An immediate mode 2D drawing API for Bevy game engine

Bevy Canvas API prototype An unofficial immediate mode 2D drawing API for Bevy game engine. Check the documentation or the examples to know how to use

Federico Rinaldi 20 Apr 21, 2022
Simple RUST game with the Bevy Engine

Simple RUST Game using the Bevy Engine YouTube videos for this code base: Episode 1 - Rust Game Development tutorial from Scratch with Bevy Engine Epi

null 150 Jan 7, 2023
A vdom-free reactive UI lib for the bevy game engine

ui4 ui4 is my fourth major attempt at making a UI dataflow library for the Bevy game engine. More specifically, it's a vdom-less UI library which uses

null 48 Nov 28, 2022
Hanabi — a particle system plugin for the Bevy game engine.

Hanabi — a particle system plugin for the Bevy game engine

Jerome Humbert 256 Dec 30, 2022
Brine is my attempt at writing a Minecraft client in Rust using the Bevy game engine.

Brine Brine is my attempt at writing a Minecraft client in Rust using the Bevy game engine. It's EXTREMELY work-in-progress. The thing that makes Brin

Ben Reeves 34 Dec 26, 2022
Bevy is a refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

John Winston 3 Jun 3, 2022
Plotting library for the Bevy game engine with a focus on esthetics and interactivity

Plotting library for the Bevy game engine with a focus on esthetics and interactivity. It can handle both data points (see the "minimal", "markers", a

Eli 40 Dec 25, 2022
Utilities for creating strictly ordered execution graphs of systems for the Bevy game engine

bevy_system_graph This crate provides the utilities for creating strictly ordered execution graphs of systems for the Bevy game engine. Bevy Version S

Hourai Teahouse 19 Dec 2, 2022