Skip to content

subsequent tweening of the same property #70

@debris

Description

@debris

I have the following pieces of code. One of them (A) - DOES NOT work as expected, and the other one (B) - DOES work as expected. I do not understand why.

The only difference between them is calling commands.entity(card).animation() vs commands.animation().

code A

fn on_fix_card_positions(
    _trigger: On<TweenEvent<FixCardPositions>>,
    mut commands: Commands,
    player_cards: Query<(Entity, &Transform), With<PlayerCard>>,
) {

    for (i, (card, transform)) in player_cards.iter().enumerate() {
        let target_translation = Vec3::new(-160. - (i as f32 * 80.), 0., 0.);

        
        commands.entity(card).animation()
            .insert(sequence((
                forward(Duration::from_secs_f32(CARD_ANIMATION_TIME * i as f32)),
                tween(
                    Duration::from_secs_f32(CARD_ANIMATION_TIME),
                    EaseKind::Linear,
                    card.into_target().with(translation(transform.translation, target_translation))
                ),
            )));

code B

fn on_fix_card_positions(
    _trigger: On<TweenEvent<FixCardPositions>>,
    mut commands: Commands,
    player_cards: Query<(Entity, &Transform), With<PlayerCard>>,
) {

    for (i, (card, transform)) in player_cards.iter().enumerate() {
        let target_translation = Vec3::new(-160. - (i as f32 * 80.), 0., 0.);

        commands.animation()
            .insert(sequence((
                forward(Duration::from_secs_f32(CARD_ANIMATION_TIME * i as f32)),
                tween(
                    Duration::from_secs_f32(CARD_ANIMATION_TIME),
                    EaseKind::Linear,
                    card.into_target().with(translation(transform.translation, target_translation))
                ),
            )));

How to reproduce the problem? and what is the problem?

  1. I trigger FixCardPositions event for the first time. Everything works as expected. Let's call it Animation 1.
  2. Sometime later, long after the animations finished executing, I trigger FixCardPosition event again. Let's call it Animation 2.
  3. if code A is executed, some weird glitches appear. Triggering FixCardPosition the 2nd time, sometimes trigger Animation 1 to run again, and then Animation 2. Sometimes the animation does not happen at all. And sometimes the Translation is simply set to Vec3::ZERO.
  4. if code B is executed, none of the glitches appear. The animation is always consistent and behaves exactly as I expect.

The only difference between the two is calling commands.entity(card).animation() vs commands.animation(). Am I missing something here? Or using the crate incorrectly? Also, are finished animations ever pruned? It seems like calling commands.animation() pernamently adds child objects to the world

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