Skip to content

impl AnimationBuilderExt for EntityWorldMut / RelatedSpawner<ChildOf> #69

Closed as not planned

Description

@mirsella

hello !

this would allow easily adding animations when using the Children component (and so children![] macro)
use case:

let bundle = (..., Children::spawn_with(|mut p| {
	p.animation() // impl on RelatedSpawner
	p.spawn_empty() // animator as child, using EntityWorldMut impl that this spawn_empty return
});

and what about directly a component that insert the animation ? instead of using entity commands

Activity

  1. mirsella commented on Nov 3, 2025

    @mirsella
    Author

    did that:

    use bevy::{
        ecs::{component::HookContext, world::DeferredWorld},
        prelude::*,
    };
    use bevy_tween::prelude::*;
    
    pub trait AnimFn = Fn(bevy_tween::combinator::AnimationBuilder) + Send + Sync + 'static;
    
    #[derive(Component)]
    #[component(storage = "SparseSet", on_add = Self::on_add)]
    pub struct AnimationBuilder<T: AnimFn>(pub T);
    
    impl<T: AnimFn> AnimationBuilder<T> {
        fn on_add(mut world: DeferredWorld, context: HookContext) {
            let (entities, mut commands) = world.entities_and_commands();
            let inner = entities
                .get(context.entity)
                .unwrap()
                .get::<AnimationBuilder<T>>()
                .unwrap();
            let mut ec = commands.entity(context.entity);
            inner.0(ec.animation());
        }
    }
  2. Multirious commented on Oct 25, 2026

    @Multirious
    Owner

    I think we should go with improving bsn! ergonomics instead.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions