-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Split AnimationTarget
into two components
#20774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Split AnimationTarget
into two components
#20774
Conversation
How about |
|
The name "target" is used at a meta-level: no relation components have the name "target" in them. Some alternative names:
|
I guess |
Objective
Add flexibility by refactoring
AnimationTarget
into two separate components. This will smooth the path for future animation features.Background
bevy_animation
animates entities by assigning themAnimationTarget
components:player: Entity
links to an entity that contains anAnimationPlayer
component. AnAnimationPlayer
playsAnimationClip
assets.id: AnimationTargetId
identifies which tracks in anAnimationClip
apply to the target entity.When loading a glTF these components are automatically created. They can also be created manually.
Problem
The two parts of
AnimationTarget
often go together but sometimes would be better separated:AnimationTargetId
first, but not link it up to anAnimationPlayer
until later (see 🧪 Bone attachments #18262 for an example).AnimationTargetId
but not useAnimationPlayer
- maybe I've got a different component that playsAnimationClip
s.In theory
player
could be left asEntity::PLACEHOLDER
, but that's messy and will trigger a warning inanimate_targets
.Solution
This PR splits
AnimationTarget
into two components:AnimationTargetId
is just the original struct with a component derive.AnimationPlayerTarget
is a new unit struct(Entity)
.I'm not convinced
AnimationPlayerTarget
is a good name, but it does fit the usual source/target naming for entity relationships.AnimationPlayerRef
was another candidate.AnimationPlayerTarget
could be a relationship target, but there would be a performance cost from makingAnimationPlayer
a relationship source. Maybe it's still a good idea, but that's probably best left to another PR.Performance
Profiled on
many_foxes
- difference was negligible.Testing
Examples
animated_mesh
,animated_transform
,animated_ui
,animation_masks
,eased_motion
,scene_viewer
.Future
If this PR lands then I'll probably file a follow up that adds more flexibility to the the glTF loader creation of
AnimationTargetId
andAnimationPlayer
. This will help #18262 and enable some other features.