Making games in Rust with Bevy
Caitlin Sar Campbell
Gulaschprogrammiernacht 24 (GPN24) · Day 2 · ZKM Kubus
Overview
In this insightful talk from GPN24, Caitlin Sar Campbell, an independent game developer, explores the Bevy game engine built in Rust. The presentation offers a dual perspective: a technical deep dive into Bevy's architecture and a practical guide for developers working on ambitious projects. Campbell shares her experiences building a large-scale game, "Exa Factory," part-time (20 hours a week), emphasizing the challenges and advantages of using a rapidly evolving, code-first, and community-driven engine.

Key moments
- 0:00 Introduction and overview of Bevy's scope
- 4:30 Understanding Bevy's core ECS architecture
- 9:00 Building a basic interactive Bevy application
- 15:00 Controlling game flow using Bevy States
- 20:30 Organizing large Bevy projects with plugins
- 27:45 Practical challenges in Bevy game development
- 32:00 Key advantages and "easy wins" with Bevy
- 37:00 Exploring Bevy's networking solutions and libraries
Making games in Rust with Bevy
Speakers: Caitlin Sar Campbell, Independent Game Developer
Conference: GPN24
YouTube: https://www.youtube.com/watch?v=BzrZoJZcmVI
Overview
In this insightful talk from GPN24, Caitlin Sar Campbell, an independent game developer, explores the Bevy game engine built in Rust. The presentation offers a dual perspective: a technical deep dive into Bevy's architecture and a practical guide for developers working on ambitious projects. Campbell shares her experiences building a large-scale game, "Exa Factory," part-time (20 hours a week), emphasizing the challenges and advantages of using a rapidly evolving, code-first, and community-driven engine.
The talk provides a comprehensive understanding of Bevy's core principles, particularly its Entity Component System (ECS), and how it deviates from traditional game development paradigms. Campbell illustrates these concepts with clear code examples, demonstrating how to construct a functional game from scratch. Beyond the technicalities, she addresses crucial practical considerations for independent developers, such as working with artists, managing asset formats, and navigating the unique challenges of pitching a game developed with a less conventional engine like Bevy.
This presentation is highly relevant for Rust developers interested in game development, those seeking alternatives to established engines like Unity or Unreal, and anyone curious about the practical implications of adopting cutting-edge, open-source tooling. By the end of the talk, attendees gain both a theoretical grasp of Bevy's mechanics and a pragmatic outlook on building and maintaining a game within its ecosystem, highlighting the power of Rust for creating performant and maintainable interactive experiences.
Background
▶ Watch: Introduction and overview of Bevy's scope (0:00)
Traditional game development often relies on engines that employ a hierarchical, object-oriented structure, where game objects are organized into complex scene graphs. This approach, while familiar, can lead to tightly coupled systems, making parallel processing difficult and sometimes resulting in "spaghetti code" as projects grow. Furthermore, many commercial engines are proprietary, dictating specific workflows and tools, which can be a barrier for developers prioritizing open standards and a code-first approach.
Bevy emerges as a compelling alternative, challenging these traditional paradigms. It is designed from the ground up to be code-first, meaning developers primarily interact with the engine through Rust code rather than a graphical user interface (GUI) editor (though one is in development). This philosophy appeals strongly to developers who prefer to live in their text editors and have full control over their codebase. Bevy is also fundamentally data-driven, leveraging an Entity Component System (ECS) architecture, which inherently promotes data-oriented design and parallel execution.
The choice of Rust as its foundational language is central to Bevy's appeal. Rust brings guarantees of memory safety and thread safety without sacrificing performance, making it an ideal candidate for game development where performance is paramount. The Rust ecosystem, with its robust package manager Cargo and extensive collection of crates (libraries), further enhances Bevy's capabilities, allowing developers to integrate a wide array of functionalities seamlessly. Bevy also distinguishes itself by being opinionated to open standards, prioritizing formats like glTF and glb for 3D models and WebP for images, fostering an open and interoperable development environment. This combination of Rust's strengths and Bevy's unique architectural choices positions it as a powerful, albeit rapidly evolving, tool for modern game creation.
Key Findings
▶ Watch: Building a basic interactive Bevy application (9:00)
Caitlin Sar Campbell's talk highlights several key findings regarding Bevy's design, its advantages, and the practical realities of using it for game development:
- Bevy's Core Philosophy and Rapid Evolution: Bevy is characterized as rapidly changing, community-oriented, code-first, data-driven, and opinionated to open standards. Its release cycle of every 3 to 6 months introduces significant API changes, which while challenging for long-term projects, also means constant improvement and new features. This rapid progress is a double-edged sword, requiring diligent updates but delivering a continuously better engine.
- The Power of ECS: The Entity Component System (ECS) is Bevy's foundational architecture, comprising Entities (unique IDs for game objects), Components (data-only tags attached to entities), and Systems (functions that operate on entities with specific components). This flat, non-hierarchical structure enables massive parallelization of game logic by default, making Bevy exceptionally well-suited for data-heavy games like the factory simulator Campbell is building.
- Modular Code Organization with Plugins: Bevy embraces an "injection pattern all the way down" through its plugin system. Plugins are modular units that bundle systems, resources, and configurations, allowing developers to organize complex games into clean, segmented codebases, preventing the growth of monolithic files.
- Efficient State Management and Conditional Execution: Bevy's robust state management, implemented using Rust enums for game states (e.g.,
MainMenu,Playing), allows systems to run only when specific conditions are met. This, combined with schedules (e.g.,Update,Startup,OnEnterState), enables highly optimized performance by ensuring that only necessary logic executes at any given time. - Leveraging the Rust Ecosystem: Bevy fully integrates with the Rust ecosystem, providing access to Cargo for dependency management, robust tooling, and a vast array of crates. This ensures that developers benefit from Rust's performance, safety, and modern language features without compromise.
- Challenges in Collaboration and Tooling: Despite its technical strengths, Bevy presents practical difficulties, particularly for collaboration with non-developers (artists, designers). Its code-first nature currently lacks a built-in scene editor (though one is coming), making visual asset integration and iteration challenging for those unfamiliar with development tools like Git or Rust. Artists may also be unfamiliar with Bevy's preferred open asset formats like glTF/glb.
- Community-Driven Development: Bevy boasts an "anarchist organized PR and code structure" where anyone can propose features, fix bugs, and drive the engine's direction. This highly community-oriented approach fosters rapid development and allows users to directly influence the engine's evolution, a significant advantage over more closed-source or heavily structured projects.
- Easy Cross-Platform Deployment: Bevy simplifies the deployment process, allowing for the creation of single-file binaries (e.g.,
.elffor Linux,.exefor Windows) that encompass the entire game. It offers "cross-platform for free," supporting various targets including Windows, Linux, RISC-V, and ARM binaries.
Technical Deep Dive
▶ Watch: Organizing large Bevy projects with plugins (20:30)
Bevy's technical foundation is rooted in its innovative use of Rust and the Entity Component System (ECS) pattern, a departure from traditional object-oriented or scene-graph architectures. This section explores Bevy's core technical components and how they interoperate to create a powerful and flexible game engine.
The Entity Component System (ECS)
At the heart of Bevy is its ECS architecture, which promotes a data-driven design ideal for parallel processing.
- Entities: In Bevy, an entity is essentially a unique identifier—a lightweight, plain integer. It represents a "thing in itself" in the game world, such as a player character, an enemy, a bullet, or a UI element. Entities have no inherent data or behavior; they are simply containers for components.
- Components: Components are pure data structures that describe an entity's properties. They are like "tags" attached to entities. For example, a
Playerentity might havePosition,Velocity,Health, andSpritecomponents. Crucially, components are independent and contain no logic. The talk demonstrates this with aRotatingcomponent (defined as#[derive(Component)] struct Rotating;) which acts as a simple tag to identify entities that should rotate. - Systems: Systems are the functions that encapsulate the game's logic. They query for entities that possess specific combinations of components and then perform operations on those components. Systems are highly optimized for parallel execution by default. For instance, a
MovementSystemmight query for all entities withPositionandVelocitycomponents and update their positions based on their velocities.
The talk provides a concrete example of a rotate system:
This system efficiently finds all entities tagged with Rotating and updates their Transform component, demonstrating how systems act on specific data without needing to know the entity's entire hierarchy.
Plugins and Application Structure
Bevy's architecture is built on an "injection pattern all the way down," meaning everything is organized into plugins. A plugin is a modular unit that bundles related systems, resources, and configurations. The main application (App) is essentially a collection of plugins.
The most basic Bevy application starts with:
This minimal code (7 lines) is sufficient to launch an empty UI window thanks to the DefaultPlugins, which provide essential functionalities like rendering, window management, input handling, and more.
For more complex games, developers create custom plugins, such as BuildingManagementPlugin or MenuPlugin. These plugins implement the Plugin trait and use the App::add_systems, App::add_plugins, and App::insert_resource methods to configure the application. This modularity ensures code organization, prevents large, unwieldy files, and promotes reusability. A plugin can even include other plugins, creating a clean, nested structure for managing game features.
Schedules and Conditions
Schedules dictate when and in what order systems run. Common schedules include Startup (for systems that run once when the application launches) and Update (for systems that run every frame). Bevy provides many other schedules (e.g., PreStartup, PostStartup, First, Last) allowing fine-grained control over execution flow.
Conditions further refine system execution by allowing them to run only if specific criteria are met. This is a powerful optimization technique. For example, run_if(in_state(GameState::Playing)) ensures a system only executes when the game is in the Playing state, preventing unnecessary computations when in a menu or paused state. Conditions eliminate the need for verbose if statements within systems, leading to cleaner and more performant code.
Resources and State Management
Resources are singletons—unique pieces of data accessible by any system throughout the application. Unlike components, which are tied to specific entities, resources represent global state or shared data. Examples include Time (for tracking elapsed time), KeyboardInput (for keyboard events), and game states.
Bevy leverages Rust enums to implement game states. An enum like enum GameState { MainMenu, Playing, Paused } can define distinct states for the game. Systems can then be configured to on_enter(GameState::Playing) (run once when entering a state), on_exit(GameState::Paused) (run once when exiting a state), or run_if(in_state(GameState::Playing)) (run continuously while in a state).
The talk demonstrates a toggle_state system that uses the KeyboardInput resource and NextState resource to switch between GameState::Menu and GameState::Playing when the spacebar is pressed. This system also shows how on_enter_game_state_playing can be used to trigger a one-time event, like changing a sprite's color to red, when the game transitions to the playing state. This elegant state machine design ensures logic is only active when relevant, significantly improving efficiency and maintainability.
Shader Development and Networking
Bevy utilizes WebGPU for graphics rendering and WGSL (WebGPU Shading Language) for shaders. While Bevy provides a dialect of WGSL that allows importing Rust data structures, Campbell notes that this can complicate using standard WGSL tooling. Stripping out Bevy-specific elements, however, allows for standard tooling analysis.
For networking, Bevy relies on well-maintained community crates. Two prominent examples are:
- Replicon: A simpler library for server-authoritative replication. Developers can tag components with a
Replicatedcomponent, and Replicon automatically syncs these between server and client instances. This is suitable for turn-based or less "twitchy" games and offers a low barrier to entry. - Lightyear: A more advanced networking library, offering features like rollback, client-state management, prediction, and control-based game management. Lightyear is recommended for fast-paced, "twitchy" games like first-person shooters, though it has a steeper learning curve.
A significant advantage of Bevy's ECS and plugin system is the ease of creating headless server builds. By feature-gating display-related plugins, the core ECS logic can run without a graphical interface, enabling lightweight and efficient game servers. The server modifies components, and networking libraries then replicate these changes to connected clients.
Demo / Proof of Concept
▶ Watch: Practical challenges in Bevy game development (27:45)
Caitlin Sar Campbell's presentation effectively served as a live demonstration and proof of concept for Bevy's capabilities, illustrating core concepts through progressively complex code examples and their visual outputs.
The initial "demo" started with the absolute minimum: a seven-line Rust program using App::new().add_plugins(DefaultPlugins).run();. Running this code immediately produced an empty window, showcasing Bevy's ability to quickly bootstrap a graphical application. This was then expanded to include a setup system, which spawned a 2D camera and a sprite (the GPN11 logo). The audience could visually confirm the appearance of the sprite on the screen, demonstrating basic asset loading and rendering.
The talk then moved to a more dynamic demonstration. By introducing a simple Rotating component and a rotate system that queries for entities with this component and modifies their Transform based on Time, Campbell showed the GPN11 sprite continuously rotating. This highlighted Bevy's data-driven nature: adding a single component enabled a specific behavior, which could be applied to any number of entities.
Further enhancing the live code demonstration, Campbell integrated game states (GameState::Menu and GameState::Playing). A toggle_state system, triggered by the spacebar, transitioned between these states. Critically, the rotate system was configured to run_if(in_state(GameState::Playing)). The visual outcome was compelling: pressing spacebar not only changed the sprite's color to red (via an on_enter_game_state_playing system) but also paused and resumed its rotation, clearly illustrating how Bevy's state management and conditional system execution can control complex game logic dynamically and efficiently.
Beyond these live-coded examples, Campbell referenced and showed a screenshot of the official Bevy examples website. This resource provides hundreds of interactive examples, allowing developers to see Bevy code side-by-side with a running, in-browser version of the game. This serves as a powerful learning tool and a comprehensive "proof of concept" for the engine's diverse functionalities, from basic spawning to advanced rendering techniques. The speaker also mentioned her own game, "Exa Factory," as a tangible, ongoing project built with Bevy, further validating its use for large-scale development.
Defensive Implications
▶ Watch: Exploring Bevy's networking solutions and libraries (37:00)
While the talk focuses on game development rather than cybersecurity, it offers crucial "defensive implications" from a developer's perspective, emphasizing practices to build robust, maintainable, and future-proof games within the Bevy ecosystem. These are not security defenses but rather strategies to protect a project from common development pitfalls.
- Proactive Version Management Against Rapid Changes: Bevy's rapid release cycle (every 3-6 months) introduces frequent API-breaking changes. The speaker stresses the "mandatory" practice of rigorous updating. As soon as dependent crates support a new Bevy version, developers should dedicate time to update their projects. This "defense" prevents technical debt from accumulating, keeps projects aligned with the latest optimizations and features, and avoids being stuck on an outdated, unsupported version.
- Mandatory Performance Optimizations: Rust and Bevy historically had a reputation for slow compile times. Campbell advises against skipping the Bevy performance optimization guide. Implementing these optimizations is crucial for maintaining acceptable compile times and runtime performance, "otherwise you're going to have a bad time." This is a defense against frustrating development cycles and poor user experience.
- Prioritizing Accessibility from the Outset: The speaker strongly recommends prioritizing accessibility when writing any software, including Bevy games. She mentions crates like
A11Y(pronounced "ally") as resources. Integrating accessibility features (e.g., directional navigation for UI, screen reader support) from the beginning defends against excluding users and ensures a broader audience can enjoy the game. - Avoiding LLMs for Code Generation: Campbell issues a strong warning against using Large Language Models (LLMs) for generating Bevy code. She notes that LLMs often have outdated training data, spitting out code from "Bevy 0.4 and like the 2016 release," and lack understanding of Bevy's ECS architecture, leading to "the most ugly ugly code you've ever seen." Relying on LLMs in this context is a defense against introducing poorly structured, outdated, and unmaintainable code into a project.
- Strategic Collaboration with Non-Developers: Bevy's code-first nature creates a "Bevy difficulty" in collaborating with non-developer team members (artists, designers) who may be unfamiliar with Git, compiling code, or Rust. The speaker recounts making a "micro version of the game" where artists could edit a TOML file to change settings, despite their dissatisfaction. This highlights the need for defensive planning to bridge the gap, potentially by creating custom tooling or simplifying workflows for non-technical contributors, or by anticipating the upcoming official scene editor.
- Embracing Open Standards with Awareness: Bevy's opinionation towards open standards like glTF/glb is a win, but artists often prefer proprietary formats (e.g., FBX) or are unfamiliar with open-source workflows. Developers must "defend" against friction by providing onboarding and education on these formats, understanding potential mismatches in artistic pipelines.
- Leveraging the Community for Support: Bevy's community-oriented structure means developers can contribute patches, propose features, and seek help. Engaging with this "talkative community" is a defense mechanism against getting stuck on issues or needing features, as upstream contributions can quickly integrate desired functionalities.
Key Takeaways
- ECS is transformative: Bevy's Entity Component System (ECS) architecture (Entities, Components, Systems) fundamentally enables highly performant, parallelized, and modular game logic, making it ideal for data-heavy games.
- Rapid evolution, managed updates: Bevy's frequent releases (every 3-6 months) offer continuous improvements and new features but necessitate rigorous and proactive updating to manage API-breaking changes and maintain dependency compatibility.
- Code-first, plugin-driven modularity: Bevy's code-first philosophy, coupled with its "injection pattern all the way down" plugin system, encourages clean, organized, and reusable code, preventing "spaghetti code" in complex projects.
- Smart state and system control: Leveraging Rust enums for game states and Bevy's schedules and conditions allows for precise control over when systems run, optimizing performance by executing logic only when relevant.
- Rust ecosystem advantages: Bevy fully benefits from the Rust ecosystem, including Cargo, robust tooling, and a vast array of crates, providing a powerful and safe development environment without compromise.
- Collaboration challenges (and solutions): The lack of a native scene editor (currently, though one is coming) and preference for open standards can complicate collaboration with non-technical team members, requiring developers to devise custom tooling or onboarding strategies.
About the Speaker(s)
Caitlin Sar Campbell is an independent game developer with a strong passion for Rust and open tooling. She is actively working part-time (20 hours a week) on a large-scale factory game called "Exa Factory," built entirely with the Bevy game engine. Her experience as a Rust developer and her commitment to the Bevy ecosystem are evident through her contributions, such as submitting patches for issues like KTX2 texture parsing. Campbell's talk provides insights from the perspective of someone deeply engaged in practical game development, navigating the cutting edge of open-source game engines.
Reviews
Dr. Zero (Offensive Security Researcher) — SOLID
A competent Bevy tutorial that delivers what it promises: here's ECS, here's how plugins work, here's how to get started. Nothing wrong with it, but also nothing that isn't in the Bevy book or any of a dozen YouTube tutorials. It's a conference intro talk, not a research contribution.
Heather Calloway (CISO) — SOLID
A competent technical introduction to a Rust-based game engine. Zero enterprise security relevance. If you're not building games in Rust, there's nothing here for your program.