bevy
bevy copied to clipboard
Playing multiple animations on a glb model produces a lot of warnings
Bevy version
0.12.1 (edited)
What you did
I try to switch between different animations on the same .glb model when certain keys are pressed and then released. It's based off the animated_fox example and also uses "L" for looping and arrow keys to speed up the animation (as seen in the video)
https://github.com/bevyengine/bevy/assets/29583449/492f170c-c058-4ca9-8a6c-0953007f67e8
:
main.rs:
pub struct Animations(pub Vec<Handle<AnimationClip>>);
commands.insert_resource(Animations(vec![
asset_server.load("model/animated/shift_stick.glb#Animation0"),
asset_server.load("model/animated/Generator.glb#Animation0"),
asset_server.load("model/animated/Generator.glb#Animation1")
]));
commands.spawn(HookedSceneBundle {
scene: SceneBundle { scene: asset_server.load("model/animated/shift_stick.glb#Scene0"), ..default() },
hook: SceneHook::new(|entity, cmds| {
if entity.contains::<AnimationPlayer>() {
cmds.insert(AnimateThese(HashMap::from([("shift_stick".to_string(), vec![1])])));
}
}),
});
commands.spawn(HookedSceneBundle {
scene: SceneBundle { scene: asset_server.load("model/animated/Generator.glb#Scene0"),
transform,
..default()
},
hook: SceneHook::new(|entity, cmds| {
if entity.contains::<AnimationPlayer>() {
cmds.insert(AnimateThese(HashMap::from([("Generator".to_string(), vec![2, 3])])));
}
}),
});
keyboard.rs
if keyboard_input.just_released(KeyCode::Key1) {
ev_animate_index.send(AnimateIndexEvent { index: 1 });
}
if keyboard_input.just_released(KeyCode::Key2) {
ev_animate_index.send(AnimateIndexEvent { index: 2 });
}
if keyboard_input.just_released(KeyCode::Key3) {
ev_animate_index.send(AnimateIndexEvent { index: 3 });
}
animations.rs
pub fn animate_sys(
animations: Res<Animations>,
mut query: Query<(&mut AnimationPlayer, &AnimateThese)>,
mut events: EventReader<AnimateIndexEvent>,
) {
for to_animate in events.read() {
let mut foundAPlayer = false;
for (mut player, animateThisOne) in query.iter_mut() {
if foundAPlayer {
break;
}
for vector in animateThisOne.0.iter() {
if foundAPlayer {
break;
}
for index in vector.1.iter() {
let current_index: usize = usize::try_from(to_animate.index).unwrap();
if *index == current_index {
player.play_with_transition(
animations.0[*index-1].clone_weak(),
Duration::from_millis(250),
);
// foundAPlayer = true;
break;
}
}
}
}
}
}
What went wrong
I expected animation[0] to play for the "shift_stick" model when pressing+releasing key "1" which it does. I expected animation[1] to play on key "2" for the "Generator" model and animation[2] to play on key "3" press for the same and they both do.
But after presing "2" or "3" / playing the first or second animation for the Generator model just once the program constantly keeps spilling the same message to console "WARN bevy_animation: Animation player on 21v0 did not match any entity paths." (21 could be any other number on any run of the program) . This will continue until i kill the app.
I think this cannot be ignored. I suspect it will kill the app at some point and also makes debugging via console logging impossible.
Note: foundPlayer = true is commented out. If i enable it, only the 1/ 2 Generator animations can be played while still spamming the console with "WARN bevy_animation: Animation player on 21v0 did not match any entity paths."
Additional information
#11318 seems to be related.
The animation player for multiple models and multiple animations is very confusing to me. There seems to be no way to identify multiple players that are created when loading animations for a model. Or am I doing it the right way? I don't know how to select the correct player for animation 1 or 2 of the "Generator" model.
"Generator.glb" models a machine with a piston and a turning wheel, that should be animated separately, eventually at different speeds. I could not find any info that says that you must have a common root node in Blender for a "good style" like i read in another ticket about animation problems. It seems to be custom to just have a scene collection and different parts in a blender model, so i don't think the problem is "bad modelling" in blender and #11318 seems to prove that.