Skip to content

AnimationPlayer can play unrelated AnimationClips  #8357

Closed
@nicopap

Description

@nicopap

bevy version: main commit dff071c

What you did

I tried to play a Handle<AnimationClip> which animates X (using entity path) on a AnimationPlayer component of entity Y, and the animation played.

What went wrong

The animation played, when the given animation is not supposed to work with this entity. the issue lies in

fn find_bone(
root: Entity,
path: &EntityPath,
children: &Query<&Children>,
names: &Query<&Name>,
path_cache: &mut Vec<Option<Entity>>,
) -> Option<Entity> {
// PERF: finding the target entity can be optimised
let mut current_entity = root;
path_cache.resize(path.parts.len(), None);
// Ignore the first name, it is the root node which we already have
for (idx, part) in path.parts.iter().enumerate().skip(1) {

The name of the root entity is entirely dismissed.

I have three different animated meshes, each with their own AnimationPlayer component.
I have a collection of Handle<AnimationClip>, each AnimationClip is relevant to a single of three meshes (AnimationClip even contains a path to the animated entities).
I can call AnimationPlayer::play on component of entity 1, with an Handle<AnimationClip> containing an animation for entity 2.
This is wrong, it should be impossible to do that.

Ideal implementation

It is possible to check for compatibility in find_bone, return None and print a warning, but ideally, the AnimationPlayer::play method should be able to fail if given the wrong Handle<AnimationClip>, and users should be given a way to test for animation compatibility. This way, it's actually possible to do something about it.

Additional information

This was found it because using the wrong animation on the wrong entity causes a panic with morph targets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AnimationMake things move and change over timeC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions