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
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 texture
spawner
3d/spawner.rs
Renders a large number of cubes with changing position and material
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
wireframe
3d/wireframe.rs
Showcases wireframe rendering
z_sort_debug
3d/z_sort_debug.rs
Visualizes camera Z-ordering
Example
File
Description
audio
audio/audio.rs
Shows how to load and play an audio file
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
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
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
query_bundle
ecs/query_bundle.rs
Shows how to query entities that contain components in a Bundle
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_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
Example
File
Description
animate_shader
shader/animate_shader.rs
Shows how to animate a shader by accessing a time uniform variable
array_texture
shader/array_texture.rs
Illustrates how to create a texture for use with a texture2DArray shader uniform variable
hot_shader_reloading
shader/hot_shader_reloading.rs
Illustrates how to load shaders such that they can be edited while the example is still running
mesh_custom_attribute
shader/mesh_custom_attribute.rs
Illustrates how to add a custom attribute to a mesh and use it in a custom shader
shader_custom_material
shader/shader_custom_material.rs
Illustrates creating a custom material and a shader that uses it
shader_defs
shader/shader_defs.rs
Demonstrates creating a custom material that uses "shaders defs" (a tool to selectively toggle parts of a shader)
Example
File
Description
bevymark
tools/bevymark.rs
A heavy workload to benchmark your system with Bevy
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
rustup target add aarch64-apple-ios x86_64-apple-ios
cargo install cargo-lipo
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.
The Xcode build GUI will by default build the rust library for both
x86_64-apple-ios
, and aarch64-apple-ios
which may take a while. If you'd
like speed this up, you update the IOS_TARGETS
User-Defined environment
variable in the "cargo_ios
target" to be either x86_64-apple-ios
or
aarch64-apple-ios
depending on your goal.
Note: if you update this variable in Xcode, it will also change the default
used for the Makefile
.
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 headless_wasm
. For other examples in wasm/ directory,
change the headless_wasm
in the following commands and edit examples/wasm/index.html
to point to the correct .js
file.
cargo build --example headless_wasm --target wasm32-unknown-unknown --no-default-features
wasm-bindgen --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/debug/examples/headless_wasm.wasm
Then serve examples/wasm
dir to browser. i.e.
basic-http-server examples/wasm
Example
File
Description
hello_wasm
wasm/hello_wasm.rs
Runs a minimal example that logs "hello world" to the browser's console
assets_wasm
wasm/assets_wasm.rs
Demonstrates how to load assets from wasm
headless_wasm
wasm/headless_wasm.rs
Sets up a schedule runner and continually logs a counter to the browser's console
winit_wasm
wasm/winit_wasm.rs
Logs user input to the browser's console. Requires the bevy_winit
features