Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset pre-processing is applied universally, even to custom asset sources #12483

Open
eidloi opened this issue Mar 14, 2024 · 0 comments
Open
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior C-Usability A simple quality-of-life change that makes Bevy easier to use

Comments

@eidloi
Copy link

eidloi commented Mar 14, 2024

Bevy version

0,13

What you did

I have a setup where I build a re-usable map editor in one crate and place the actual game assets in another crate:

  • Workspace
    • Game Specific assets and logic
    • Map editor

Game part has a main file for starting the editor lib simple as:

use bevy::prelude::*;
use sickle::EditorPlugin;

const TITLE: &str = "My Awsome Game";

fn main() {
    App::new()
        .add_plugins(EditorPlugin(TITLE))
        .run();
}

I have a custom asset source for the editor to allow using icons, fonts, etc. from its own repository rather than having to copy it around:

pub struct EditorPlugin (pub &'static str);

impl Plugin for EditorPlugin {
    fn build(&self, app: &mut App) {
        app // reads assets from the "other" folder, rather than the default "assets" folder
            .register_asset_source(
                // This is the "name" of the new source, used in asset paths.
                // Ex: "my_editor://path/to/sprite.png"
                "my_editor",
                // This is a repeatable source builder. You can configure readers, writers,
                // processed readers, processed writers, asset watchers, etc.
                AssetSource::build()
                    .with_reader(move || {
                        Box::new(FileAssetReader::new(String::from("../my_editor/assets")))
                    }),
            );
            // and other plugins ofc,
    }
}

I enabled asset preprocessing for the game assets to get MipMaps generated for 3D assets.

[dependencies]
bevy = { version = "0.13", features = [
    "dynamic_linking",
    "file_watcher",
    "embedded_watcher",
    "asset_processor",
    "basis-universal",
] }
my_editor= { path = "../my_editor" }

And in the editor plugin:

.add_plugins(
                DefaultPlugins                    
                    .set(AssetPlugin {
                        mode: AssetMode::Processed,
                        file_path: "assets".into(),
                        processed_file_path: "imported_assets".into(),
                        ..default()
                    }),
            )

What went wrong

  1. The file_path and the processed_file_path MUST be set for the AssetPlugin, otherwise it'll panic.
  2. The target folder MUST be created manually
  3. The custom asset source logs errors without adding a preprocessor:
                AssetSource::build()
                    .with_reader(move || {
                        Box::new(FileAssetReader::new(String::from("../my_editor/assets")))
                    })
                    .with_processed_reader(move || {
                        Box::new(FileAssetReader::new(String::from("../my_editor/assets")))
                    }),
  1. The custom asset source will work, but will log a warn:
    2024-03-13T21:06:18.631377Z WARN bevy_asset::processor: Failed to remove non-existent meta "log": encountered an io error while loading asset: File not found. (os error 2)

Additional information

It still works in this setup. The icons are taken from the regular asset folder after the redirect, but it should not be enforced on all asset sources universally, nor it should look for a log file that was never generated.
NOTE: Embedded watcher was required too.

@eidloi eidloi added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 14, 2024
@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A simple quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior C-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

No branches or pull requests

2 participants