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?
- I trigger
FixCardPositions event for the first time. Everything works as expected. Let's call it Animation 1.
- Sometime later, long after the animations finished executing, I trigger
FixCardPosition event again. Let's call it Animation 2.
- 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.
- 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
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()vscommands.animation().code A
code B
How to reproduce the problem? and what is the problem?
FixCardPositionsevent for the first time. Everything works as expected. Let's call it Animation 1.FixCardPositionevent again. Let's call it Animation 2.FixCardPositionthe 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.The only difference between the two is calling
commands.entity(card).animation()vscommands.animation(). Am I missing something here? Or using the crate incorrectly? Also, are finished animations ever pruned? It seems like callingcommands.animation()pernamently adds child objects to the world