Skip to content

Add a curve sampling method to the AnimationClip API#24152

Merged
alice-i-cecile merged 1 commit into
bevyengine:mainfrom
Hilpogar:root-motion-part-1
May 7, 2026
Merged

Add a curve sampling method to the AnimationClip API#24152
alice-i-cecile merged 1 commit into
bevyengine:mainfrom
Hilpogar:root-motion-part-1

Conversation

@Hilpogar

@Hilpogar Hilpogar commented May 6, 2026

Copy link
Copy Markdown
Contributor

Objective

Add a method to AnimationClip to sample a property at a specific time. This is the first point proposed in #23355. The original goal was to allow the development of root motion, but it turns out that this API improvement can be useful for third party crates or games that need to sample animation curves directly. This PR is also inspired by the previous work in #16395.

Solution

Add a method sample_clamped to AnimationClip :

pub fn sample_clamped<P: AnimatableProperty>(
    &self,
    animatable_property: P,
    target: AnimationTargetId,
    time: f32,
) -> Option<P::Property> {}

This method requires to add another sample_clamped method to the AnimationCurve trait:

fn sample_clamped(&self, t: f32) -> Box<dyn Any>;

Testing

There is 2 new tests. One at the AnimationCurve level and one at the AnimationClip level. There is also an example in the method's documentation.

@Hilpogar Hilpogar force-pushed the root-motion-part-1 branch from 3964341 to 7410554 Compare May 6, 2026 08:55
@mnmaita mnmaita added C-Feature A new feature, making something new possible A-Animation Make things move and change over time D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 6, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Animation May 6, 2026
@alice-i-cecile

Copy link
Copy Markdown
Member

@emberlightstudios I'd love your review here :)

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly simple and well-motivated.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 7, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 7, 2026
Merged via the queue into bevyengine:main with commit 1dce255 May 7, 2026
48 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Animation May 7, 2026
@emberlightstudios

emberlightstudios commented May 18, 2026

Copy link
Copy Markdown

Sorry, I got side tracked with life stuff and had to shelve my project for some time. It looks good, but I see everyone already agreed on that.

@Hilpogar

Copy link
Copy Markdown
Contributor Author

@emberlightstudios No problem, thank you for your original proposition it helped me a lot for the implementation ! This PR was for one of the intermediate steps but the final part is not merge yet. I would be happy to have your review if you have the time : #24201

mbrea-c added a commit to mbrea-c/bevy_animation_graph that referenced this pull request Jul 11, 2026
…nodes (#153)

Thanks to bevyengine/bevy#24152, we can now get
rid of the transmute hack for sampling animation clips!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Animation Make things move and change over time C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants