Bevy Version:0.12(outdated!)

As this page is outdated, please refer to Bevy's official migration guides while reading, to cover the differences: 0.12 to 0.13, 0.13 to 0.14. 0.14 to 0.15.

I apologize for the inconvenience. I will update the page as soon as I find the time.


Browser (WebAssembly)

Introduction

You can make web browser games using Bevy. This chapter will help you with the things you need to know to do it. This page gives an overview of Bevy's Web support.

Your Bevy app will be compiled for WebAssembly (WASM), which allows it to be embedded in a web page and run inside the browser.

Performance will be limited, as WebAssembly is slower than native code and does not currently support multithreading.

Not all 3rd-party plugins are compatible. If you need extra unofficial plugins, you will have to check if they are compatible with WASM.

Project Setup

The same Bevy project, without any special code modifications, can be built for either web or desktop/native.

However, you will need a "website" with some HTML and JavaScript to contain the game, so that the browser can load, run, and display it.

For development and testing, this can just be a minimal shim. It can be easily autogenerated.

To deploy, you will need a server to host your website for other people to access. You could use GitHub's hosting service: GitHub Pages. You can also host your game on itch.io.

Additional Caveats

When users want to play your game, their browser will need to download the files. Optimizing for size is important, so that your game can start faster and not waste data bandwidth.

Note: the dynamic_linking feature flag is not supported for WASM builds. You cannot use it.

Quick Start

First, add WASM support to your Rust installation. Using Rustup:

rustup target install wasm32-unknown-unknown

wasm-server-runner

The easiest and most automatic way to get started is the wasm-server-runner tool. It is great for testing during development.

Install it:

cargo install wasm-server-runner

Set up cargo to use it, in .cargo/config.toml (in your project folder, or globally in your user home folder):

[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"

Alternatively, you can also set the runner using an environment variable:

export CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-server-runner

Now you can just run your game with:

cargo run --target wasm32-unknown-unknown

It will automatically run a minimal local webserver and open your game in your browser.

Higher-level Tools

Here are some higher-level alternatives. These are feature-rich tools that can do more for you and automate much of your workflow, but are opinionated in how they work.

Custom Web Page

If you are a web developer and you want to make your own website where you embed your Bevy game, see here.