#gamedev #networking #wasm #bevy

bevy_web_asset

Bevy asset loader that transparently supports loading over http(s)

5 releases (breaking)

Uses new Rust 2021

0.5.0 Nov 13, 2022
0.4.0 Jul 31, 2022
0.3.0 Apr 18, 2022
0.2.0 Jan 10, 2022
0.1.0 Sep 18, 2021

#343 in WebAssembly

Download history 4/week @ 2022-08-13 5/week @ 2022-08-20 10/week @ 2022-08-27 17/week @ 2022-09-03 19/week @ 2022-09-10 47/week @ 2022-09-17 8/week @ 2022-09-24 9/week @ 2022-10-01 29/week @ 2022-10-08 8/week @ 2022-10-15 33/week @ 2022-10-22 18/week @ 2022-10-29 19/week @ 2022-11-05 58/week @ 2022-11-12 41/week @ 2022-11-19 20/week @ 2022-11-26

143 downloads per month

MIT/Apache

74KB
106 lines

Bevy Web Asset

crates.io MIT/Apache 2.0 crates.io docs.rs

This is a tiny crate that that wraps the standard bevy asset loader, and adds the ability to load assets from http and https urls.

Supports both wasm (web-sys) and native.

If asset paths start with http:// or https://, then we try to do a web request to load the asset, otherwise, we just call the normal asset io.

This is nice if you want to keep your content on a server, even when developing native games. Use cases can be:

  • Tuning game balance post-launch
  • Seasonal events (halloween theme etc.)
  • Downloading dynamic content from 3rd party services (lospec, gltf repositories etc.)
  • Sharing user-created assets/mods over some service (level editor etc.)
  • Keeping initial download size small
  • Testing with different online assets during development

Usage

NOTE: You need to add the plugin instead of AssetPlugin and before DefaultPlugins:

Bevy 0.7 users, see the 0.3.0 readme for how to add the plugin.

Bevy 0.8 users, see the 0.4.0 readme for how to add the plugin.

use bevy::prelude::*;
use bevy_web_asset::WebAssetPlugin;

fn main() {
    App::new()
        // The `WebAssetPlugin` must be inserted instead of `AssetPlugin` and before `DefaultPlugins`
        .add_plugin(WebAssetPlugin::default())
        .add_plugins(DefaultPlugins.build().disable::<AssetPlugin>())
        // ...
        .run();
}

But using it is quite simple, just use http urls instead of regular asset paths.

let font: Handle<Font> = asset_server.load("https://example.com/fonts/quicksand-light.ttf");

Or:

commands.spawn(SpriteBundle {
    // Simply use a url where you would normally use an asset folder relative path
    texture: asset_server.load("https://johanhelsing.studio/assets/favicon.png"),
    ..default()
});

Bevy version support

I intend to support the latest bevy release in the main branch.

Fixes against the Bevy main branch goes in the the bevy-main branch and are merged back into main whenever bevy is released.

bevy bevy_web_asset
main bevy-main
0.9 0.5, main
0.8 0.4
0.7 0.3
0.6 0.2
0.5 0.1

Dependencies

~11–25MB
~485K SLoC