Skip to content

AnimationPlayer doesn't explain how it is created #14852

Open
@aecsocket

Description

How can Bevy's documentation be improved?

bevy_animation::AnimationPlayer doesn't explain:

  • how you should create an animation player
  • if you even should create an animation player manually
  • how this interacts with AnimationTransitions and glTF scenes

When I was trying to spawn an entity with animations, I was following the animated fox example, but tried to simplify it. My code looked approximately like:

let mut anim_player = AnimationPlayer::default();
let mut transitions = AnimationTransitions::new();

transitions
    .play(&mut anim_player, idle_animation, Duration::ZERO)
    .repeat();

commands
    .spawn((
        SceneBundle {
            scene: my_entity_gltf_scene.clone(),
            ..default()
        },
        anim_player,
        transitions,
        my_anim_graph.clone(),
    ));

However, this is wrong because here I'm creating my own AnimationPlayer, when I should actually be using the player created by the scene when it's instantiated. What I actually have to do is spawn the SceneBundle in one system, wait for the scene to be instantiated, and use a second system to use the automatically-created AnimationPlayer (I assume because the scene automatically populates it with some important data?). It's not really documented that this is specifically how you're meant to do this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-AnimationMake things move and change over timeC-DocsAn addition or correction to our documentationC-ExamplesAn addition or correction to our examplesD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions