What happens if I start tweening an property that is already being tweened #29
-
I'm probably overlooking an obvious point in documentation, but how do tweens override each other? Is this behavior customizable? For example, what happens internally if I do this?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Great question, thank you! I have internal documentation for this behavior, but decided not to overwhelm users in the public docs. The latest alive tween will overwrite all the previous tweens on the same target. So in the case of your example, for the first second, the image's color will be animated from white to black, then the color will change abruptly to somewhat reddish, and for the next 9f seconds, it will be animated towards blue. So in this particular case, you should stop the previous long tween before starting a new one to prevent this, I assume, undesirable behavior. A similar conflict may happen if duplicated tweens have startDelay or endDelay: while one tween is waiting, the other running tween will take precedence. So stopping the previous tween before creating a new one is also recommended in this case. But in the most common scenario, when you animate the same target with the same duration (and both startDelay and endDelay are 0f), tween duplicates are fine. The last created tween will overwrite all the previous ones. PrimeTween can process thousands of tweens per frame even on low-end mobile devices, so a couple of duplicated tweens is not an issue. If your project can potentially create a tween duplicate every frame, only then I recommend stopping the previous tween before creating a new one, which requires you to store the Tween reference and call tween.Stop(). But if there are only a few potential tween duplicates now and there, it's okay to ignore them in favor of simpler code. More info on this topic. |
Beta Was this translation helpful? Give feedback.
Great question, thank you! I have internal documentation for this behavior, but decided not to overwhelm users in the public docs.
The latest alive tween will overwrite all the previous tweens on the same target. So in the case of your example, for the first second, the image's color will be animated from white to black, then the color will change abruptly to somewhat reddish, and for the next 9f seconds, it will be animated towards blue. So in this particular case, you should stop the previous long tween before starting a new one to prevent this, I assume, undesirable behavior.
A similar conflict may happen if duplicated tweens have startDelay or endDelay: while one tween is waiting, the…