How can I create and use duplicate entities with animations in bevy? The animation for the following seems to work fine if I only load a single fish. If I load multiple, the animations don't play.
struct Animations(Vec<Handle<AnimationClip>>);
fn setup_fish(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut rng: ResMut<Rng>,
) {
commands.insert_resource(Animations(vec![
asset_server.load("models/Fish_anim.gltf#Animation0"),
]);
let scene: Handle<Scene> = asset_server.load("models/Fish_anim.gltf#Scene0");
for _ in 0..10 {
commands
.spawn_bundle(TransformBundle {
local: Transform::from_xyz(
rng.gen_range(10.0..20.0),
rng.gen_range(1.0..10.0),
rng.gen_range(10.0..20.0)),
global: GlobalTransform::identity(),
})
.with_children(|parent| {
parent.spawn_scene(scene.clone());
})
.insert(Fish);
}
}
fn setup_scene_once_loaded(
animations: Res<Animations>,
mut players: Query<&mut AnimationPlayer, Added<AnimationPlayer>>,
) {
for mut player in players.iter_mut() {
player.play(animations.0[0].clone_weak()).repeat();
}
}