Asset pre-processing is applied universally, even to custom asset sources
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## 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:
``` rust
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:
``` rust
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.
``` toml
[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:
``` rust
.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
2) The custom asset source logs errors without adding a preprocessor:
``` rust
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")))
}),
```
4) 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.
Contributor guide
Assessment
This issue has not been assessed yet.