These examples demonstrate the main features of Bevy and how to use them.
To run an example, use the command cargo run --example <Example>
, and add the option --features x11
or --features wayland
to force the example to run on a specific window compositor, e.g.
cargo run --features wayland --example hello_world
⚠️ Note: for users of releases on crates.io!
There are often large differences and incompatible API changes between the latest crates.io release and the development version of Bevy in the git main branch!
If you are using a released version of bevy, you need to make sure you are viewing the correct version of the examples!
When you clone the repo locally to run the examples, use git checkout
to get the correct version:
# `latest` always points to the newest release
git checkout latest
# or use a specific version
git checkout v0.4.0
Example
File
Description
hello_world
hello_world.rs
Runs a minimal example that outputs "hello world"
Example
File
Description
3d_scene
3d/3d_scene.rs
Simple 3D scene with basic shapes and lighting
lighting
3d/lighting.rs
Illustrates various lighting options in a simple scene
load_gltf
3d/load_gltf.rs
Loads and renders a gltf file as a scene
msaa
3d/msaa.rs
Configures MSAA (Multi-Sample Anti-Aliasing) for smoother edges
orthographic
3d/orthographic.rs
Shows how to create a 3D orthographic view (for isometric-look games or CAD applications)
parenting
3d/parenting.rs
Demonstrates parent->child relationships and relative transformations
pbr
3d/pbr.rs
Demonstrates use of Physically Based Rendering (PBR) properties
render_to_texture
3d/render_to_texture.rs
Shows how to render to a texture, useful for mirrors, UI, or exporting images
two_passes
3d/two_passes.rs
Shows how to render multiple passes to the same window, useful for rendering different views or drawing an object on top regardless of depth
shadow_caster_receiver
3d/shadow_caster_receiver.rs
Demonstrates how to prevent meshes from casting/receiving shadows in a 3d scene
shadow_biases
3d/shadow_biases.rs
Demonstrates how shadow biases affect shadows in a 3d scene
spherical_area_lights
3d/spherical_area_lights.rs
Demonstrates how point light radius values affect light behavior.
texture
3d/texture.rs
Shows configuration of texture materials
update_gltf_scene
3d/update_gltf_scene.rs
Update a scene from a gltf file, either by spawning the scene as a child of another entity, or by accessing the entities of the scene
vertex_colors
3d/vertex_colors.rs
Shows the use of vertex colors
wireframe
3d/wireframe.rs
Showcases wireframe rendering
3d_shapes
3d/shapes.rs
A scene showcasing the built-in 3D shapes
Example
File
Description
audio
audio/audio.rs
Shows how to load and play an audio file
audio_control
audio/audio_control.rs
Shows how to load and play an audio file, and control how it's played
ECS (Entity Component System)
Example
File
Description
ecs_guide
ecs/ecs_guide.rs
Full guide to Bevy's ECS
component_change_detection
ecs/component_change_detection.rs
Change detection on components
custom_query_param
ecs/custom_query_param.rs
Groups commonly used compound queries and query filters into a single type
event
ecs/event.rs
Illustrates event creation, activation, and reception
fixed_timestep
ecs/fixed_timestep.rs
Shows how to create systems that run every fixed timestep, rather than every tick
generic_system
ecs/generic_system.rs
Shows how to create systems that can be reused with different types
hierarchy
ecs/hierarchy.rs
Creates a hierarchy of parents and children entities
iter_combinations
ecs/iter_combinations.rs
Shows how to iterate over combinations of query results.
parallel_query
ecs/parallel_query.rs
Illustrates parallel queries with ParallelIterator
removal_detection
ecs/removal_detection.rs
Query for entities that had a specific component removed in a previous stage during the current frame.
startup_system
ecs/startup_system.rs
Demonstrates a startup system (one that runs once when the app starts up)
state
ecs/state.rs
Illustrates how to use States to control transitioning from a Menu state to an InGame state
system_chaining
ecs/system_chaining.rs
Chain two systems together, specifying a return type in a system (such as Result
)
system_closure
ecs/system_closure.rs
Show how to use closures as systems, and how to configure Local
variables by capturing external state
system_param
ecs/system_param.rs
Illustrates creating custom system parameters with SystemParam
system_sets
ecs/system_sets.rs
Shows SystemSet
use along with run criterion
timers
ecs/timers.rs
Illustrates ticking Timer
resources inside systems and handling their state
Example
File
Description
scene
scene/scene.rs
Demonstrates loading from and saving scenes to files
These examples are used to test the performance and stability of various parts of the engine in an isolated way.
Due to the focus on performance it's recommended to run the stress tests in release mode:
cargo run --release --example < example name>
Example
File
Description
bevymark
stress_tests/bevymark.rs
A heavy sprite rendering workload to benchmark your system with Bevy
many_cubes
stress_tests/many_cubes.rs
Simple benchmark to test per-entity draw overhead. Run with the sphere
argument to test frustum culling.
many_foxes
stress_tests/many_foxes.rs
Loads an animated fox model and spawns lots of them. Good for testing skinned mesh performance. Takes an unsigned integer argument for the number of foxes to spawn. Defaults to 1000.
many_lights
stress_tests/many_lights.rs
Simple benchmark to test rendering many point lights. Run with WGPU_SETTINGS_PRIO=webgl2
to restrict to uniform buffers and max 256 lights.
many_sprites
stress_tests/many_sprites.rs
Displays many sprites in a grid arragement! Used for performance testing.
transform_hierarchy.rs
stress_tests/transform_hierarchy.rs
Various test cases for hierarchy and transform propagation performance
Example
File
Description
scene_viewer
tools/scene_viewer.rs
A simple way to view glTF models with Bevy. Just run cargo run --release --example scene_viewer -- /path/to/model.gltf#Scene0
, replacing the path as appropriate. With no arguments it will load the FieldHelmet glTF model from the repository assets subdirectory.
Example
File
Description
button
ui/button.rs
Illustrates creating and updating a button
font_atlas_debug
ui/font_atlas_debug.rs
Illustrates how FontAtlases are populated (used to optimize text rendering internally)
text
ui/text.rs
Illustrates creating and updating text
text_debug
ui/text_debug.rs
An example for debugging text layout
ui
ui/ui.rs
Illustrates various features of Bevy UI
Platform-Specific Examples
rustup target add aarch64-linux-android armv7-linux-androideabi
cargo install cargo-apk
The Android SDK must be installed, and the environment variable ANDROID_SDK_ROOT
set to the root Android sdk
folder.
When using NDK (Side by side)
, the environment variable ANDROID_NDK_ROOT
must also be set to one of the NDKs in sdk\ndk\[NDK number]
.
To run on a device setup for Android development, run:
cargo apk run --example android
⚠️ At this time Bevy does not work in Android Emulator.
When using Bevy as a library, the following fields must be added to Cargo.toml
:
[package .metadata .android ]
build_targets = [" aarch64-linux-android" , " armv7-linux-androideabi" ]
target_sdk_version = 29
min_sdk_version = 16
Please reference cargo-apk
README for other Android Manifest fields.
Bevy by default targets Android API level 29 in its examples which is the
Play Store's minimum API to upload or update apps .
Users of older phones may want to use an older API when testing.
To use a different API, the following fields must be updated in Cargo.toml:
[package .metadata .android ]
target_sdk_version = >>API<<
min_sdk_version = >>API or less<<
Example
File
Description
android
android/android.rs
The 3d/3d_scene.rs
example for Android
You need to install the correct rust targets:
aarch64-apple-ios
: iOS devices
x86_64-apple-ios
: iOS simulator on x86 processors
aarch64-apple-ios-sim
: iOS simulator on Apple processors
rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
Using bash:
In an ideal world, this will boot up, install and run the app for the first
iOS simulator in your xcrun simctl devices list
. If this fails, you can
specify the simulator device UUID via:
DEVICE_ID=${YOUR_DEVICE_ID} make run
If you'd like to see xcode do stuff, you can run
open bevy_ios_example.xcodeproj/
which will open xcode. You then must push the zoom zoom play button and wait
for the magic.
Example
File
Description
ios
ios/src/lib.rs
The 3d/3d_scene.rs
example for iOS
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli
Following is an example for lighting
. For other examples, change the lighting
in the
following commands.
cargo build --release --example lighting --target wasm32-unknown-unknown
wasm-bindgen --out-name wasm_example --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/release/examples/lighting.wasm
The first command will build the example for the wasm target, creating a binary. Then,
wasm-bindgen-cli is used to create
javascript bindings to this wasm file, which can be loaded using this
example HTML file .
Then serve examples/wasm
directory to browser. i.e.
# cargo install basic-http-server
basic-http-server examples/wasm
# with python
python3 -m http.server --directory examples/wasm
# with ruby
ruby -run -ehttpd examples/wasm
To load assets, they need to be available in the folder examples/wasm/assets. Cloning this
repository will set it up as a symlink on Linux and macOS, but you will need to manually move
the assets on Windows.