Let AnimationPlayer
play clips without a graph
#18852
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Simplify playing animations when the full power of an
AnimationGraph
is not required - allow the user to skip creating a graph and instead passAnimationClip
assets directly toAnimationPlayer
.Why A Draft?
I think this PR is a failure. I'm submitting it anyway in case that leads to discussion, or someone wants to try adapting the design.
Background
In Bevy 0.13, users played animations by passing a
Handle<AnimationClip>
to various play functions inAnimationPlayer
. Bevy 0.14 addedAnimationGraph
- now users create a graph with clip nodes that reference aHandle<AnimationClip>
, and pass anAnimationNodeIndex
toAnimationPlayer
.This change gave users more power, but also made some simple cases more complex - often users just want to play a single animation, or play a simple blend into a transition then loop.
Solution
The PR changes various
AnimationPlayer
functions to take anAnimationRef
enum, which is either anAnimationNodeIndex
or aHandle<AnimationClip>
.The interface is backwards compatible. If the user creates an
AnimationGraph
and plays anAnimationNodeIndex
then everything works as before. But if they create a graph and then play aHandle<AnimationClip>
then it's silently ignored.If the user skips creating a graph, they can play a
Handle<AnimationClip>
directly. Currently only a single clip is supported, so there's no blending or transitions -play
just replaces the current clip. If the user plays aAnimationNodeIndex
and there's no graph then it's silently ignored.Why Is This A Failure?
The PR succeeds at simplifying some cases. But in practice I expect users will find it fragile and confusing - if they're using a graph and play an
AnimationClip
then it will be silently ignored, and vice versa.The implementation is messy as it has to support both things at once, even though in practice only one will be used. And adding support for blends between multiple clips will be awkward - does that mean
AnimationTransitions
now needs a whole parallel implementation as well?TLDR: Jamming two different approaches into one
AnimationPlayer
doesn't feel like a sustainable path.Are There Alternatives?
What if
AnimationPlayer
is left unchanged and a separateAnimationClipPlayer
component is added for playing clips directly? That's a bit awkward for users and has some open questions - e.g. which component doesbevy_gltf
create? And it leavesbevy_animation
with two competing implementations.Another solution is to keep
bevy_animation
unchanged, and instead havebevy_gltf
automatically create a defaultAnimationGraph
with all the animations in the file. The user can then leave that graph unchanged if it's sufficient, or replace it with their own. The problem is that the user still needs to work out which of their clips corresponds to whichAnimationNodeIndex
.