#texture #bevy #startup #handle #assets #command #missing-texture

bevy_missing_texture

A library to help with missing textures in bevy

3 releases

0.1.2 Aug 3, 2023
0.1.1 Aug 3, 2023
0.1.0 Aug 3, 2023

#1442 in Game dev

Download history 5/week @ 2024-02-20 3/week @ 2024-02-27 3/week @ 2024-03-26 63/week @ 2024-04-02

66 downloads per month

MIT license

6KB
68 lines

Bevy library for Missing Textures

use bevy::prelude::*;
use bevy_missing_texture::*;
// Make sure to have `missing_texture.png` in your assets dir
fn main() {
    App::new()
        .add_plugins(MissingTexturePlugin)
        .add_systems(Startup, (will_fail, will_succeed));
}
// This will be replaced by the missing asset
fn will_fail(mut commands: Commands, asset_server: Res<AssetServer>, mut if_missing: ResMut<ReplaceIfMissing>) {
    let handle = asset_server.load("foo.png");
    commands.spawn(SpriteBundle {
        texture: handle.clone(),
        ..Default::default()
    });
    if_missing.push(handle);
}
// This will not be replaced by the missing asset
fn will_succeed(mut commands: Commands, asset_server: Res<AssetServer>, mut if_missing: ResMut<ReplaceIfMissing>) {
    let handle = asset_server.load("bar.png");
    commands.spawn(SpriteBundle {
        texture: handle.clone(),
        ..Default::default()
    });
    if_missing.push(handle);
}

lib.rs:

Bevy library for Missing Textures

use bevy::prelude::*;
use bevy_missing_texture::*;

// Make sure to have `missing_texture.png` in your assets dir
fn main() {
    App::new()
        .add_plugins(MissingTexturePlugin)
        .add_systems(Startup, (will_fail, will_succeed));
}
// This will be replaced by the missing asset
fn will_fail(mut commands: Commands, asset_server: Res<AssetServer>, mut if_missing: ResMut<ReplaceIfMissing>) {
    let handle = asset_server.load("foo.png");
    commands.spawn(SpriteBundle {
        texture: handle.clone(),
        ..Default::default()
    });
    if_missing.push(handle);
}
// This will not be replaced by the missing asset
fn will_succeed(mut commands: Commands, asset_server: Res<AssetServer>, mut if_missing: ResMut<ReplaceIfMissing>) {
    let handle = asset_server.load("bar.png");
    commands.spawn(SpriteBundle {
        texture: handle.clone(),
        ..Default::default()
    });
    if_missing.push(handle);
}

Dependencies

~36–73MB
~1M SLoC