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:
Mark Moissette 2024-01-31 12:30:36 +01:00 committed by GitHub
parent b105f628df
commit 7699e87aac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 7 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "bevy_gltf_components"
version = "0.2.1"
version = "0.2.2"
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."
homepage = "https://github.com/kaosat-dev/Blender_bevy_components_workflow"

View File

@ -60,7 +60,7 @@ bevy_gltf_components = { version = "0.2"}
Add the following to your `[dependencies]` section in `Cargo.toml`:
```toml
bevy_gltf_components = "0.1"
bevy_gltf_components = "0.2"
```
Or use `cargo add`:

View File

@ -1,3 +1,5 @@
use std::path::Path;
use bevy::asset::AssetPath;
use bevy::gltf::Gltf;
use bevy::utils::HashSet;
use bevy::{asset::LoadState, prelude::*};
@ -30,11 +32,18 @@ pub fn track_new_gltf(
) {
for event in events.read() {
if let AssetEvent::Added { id } = event {
let handle = asset_server
.get_id_handle(*id)
.expect("this gltf should have been loaded");
tracker.add_gltf(handle.clone());
debug!("gltf created {:?}", handle.clone());
let handle = asset_server.get_id_handle(*id);
if let Some(handle) = handle {
tracker.add_gltf(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();