I spawn an entity with several my custom components and with a scene bundle, obtained from the gltf:
let human_gltf = gltf_assets.get(&app_assets.human_gltf).unwrap();
let human_scene = human_gltf.scenes[0].clone();
commands.spawn((
Human::default(),
Player,
SceneBundle {
scene: human_scene,
..Default::default()
},
));
And now I want to play animations for entities with "Human" components:
fn update_humans(mut q: Query<(Entity, &Human)>, mut animation_player_q: Query<&AnimationPlayer>) {
for (entity, human) in q.iter_mut() {
let animation_player = animation_player_q.get(entity).unwrap();
}
}
But this fails since the Entity with Human component doesn't have an AnimationPlayer component.
So, I need somehow extract this component from the child scene which is available as a SceneInstance component on the entity.
I can get access to this SceneInstance like so:
fn update_humans(mut q: Query<(Entity, &Human, &SceneInstance)>, mut animation_player_q: Query<&AnimationPlayer>) {
for (entity, human, scene) in q.iter_mut() {
let animation_player = animation_player_q.get(entity).unwrap();
}
}
But I don't quite understand how to extract the AnimationPlayer from it...
Or maybe there must be some other way (without querying the SceneInstance?)
PS: I understand how to handle AnimationPlayers via the asset_server.load("...glb#Animation0"), but my goal is to handle them sort of manually, querying the scene