feat(bevy_gltf_components): will not panic anymore if a gltf handle cannot be found (#108)
* added some minor extra debug information * removed a useless clone() call on the gltf handle * should resolve at least a part of #102
This commit is contained in:
parent
b105f628df
commit
7699e87aac
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bevy_gltf_components"
|
name = "bevy_gltf_components"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
authors = ["Mark 'kaosat-dev' Moissette"]
|
authors = ["Mark 'kaosat-dev' Moissette"]
|
||||||
description = "Allows you to define [Bevy](https://bevyengine.org/) components direclty inside gltf files and instanciate the components on the Bevy side."
|
description = "Allows you to define [Bevy](https://bevyengine.org/) components direclty inside gltf files and instanciate the components on the Bevy side."
|
||||||
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"
|
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"
|
||||||
|
|
|
@ -60,7 +60,7 @@ bevy_gltf_components = { version = "0.2"}
|
||||||
Add the following to your `[dependencies]` section in `Cargo.toml`:
|
Add the following to your `[dependencies]` section in `Cargo.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
bevy_gltf_components = "0.1"
|
bevy_gltf_components = "0.2"
|
||||||
```
|
```
|
||||||
|
|
||||||
Or use `cargo add`:
|
Or use `cargo add`:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::path::Path;
|
||||||
|
use bevy::asset::AssetPath;
|
||||||
use bevy::gltf::Gltf;
|
use bevy::gltf::Gltf;
|
||||||
use bevy::utils::HashSet;
|
use bevy::utils::HashSet;
|
||||||
use bevy::{asset::LoadState, prelude::*};
|
use bevy::{asset::LoadState, prelude::*};
|
||||||
|
@ -30,11 +32,18 @@ pub fn track_new_gltf(
|
||||||
) {
|
) {
|
||||||
for event in events.read() {
|
for event in events.read() {
|
||||||
if let AssetEvent::Added { id } = event {
|
if let AssetEvent::Added { id } = event {
|
||||||
let handle = asset_server
|
|
||||||
.get_id_handle(*id)
|
let handle = asset_server.get_id_handle(*id);
|
||||||
.expect("this gltf should have been loaded");
|
if let Some(handle) = handle {
|
||||||
tracker.add_gltf(handle.clone());
|
tracker.add_gltf(handle.clone());
|
||||||
debug!("gltf created {:?}", handle.clone());
|
debug!("gltf created {:?}", handle);
|
||||||
|
} else {
|
||||||
|
let asset_path = asset_server.get_path(*id).unwrap_or(AssetPath::from_path(Path::new("n/a".into()))); // will unfortunatly not work, will do a PR/ discussion at the Bevy level, leaving for reference, would be very practical
|
||||||
|
warn!(
|
||||||
|
"a gltf file ({:?}) has no handle available, cannot inject components",
|
||||||
|
asset_path
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
events.clear();
|
events.clear();
|
||||||
|
|
Loading…
Reference in New Issue