Skip to content

Applying the same animation to objects in a collection through a loop #104

Answered by KyryloKuzyk
SushkoTech asked this question in FAQ
Discussion options

You must be logged in to vote

Hey! I'm glad PrimeTween is helpful for you :)

Hmm, I just copy-pasted your code and it works as expected: all objects except the last one are scaled down, then destroyed one by one.

However, I was able to replicate a similar issue to what you're describing by removing the yield return ToYieldInstruction() part. In this case, all objects are scaled down, but only the last one is destroyed. This happens because the i variable is captured in a closure inside the OnComplete() callback and its value is shared between all callbacks. The compiler also warns about this issue with the warning: "Captured variable is modified in the outer scope".

There are two ways how you can fix the issue. The fi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@SushkoTech
Comment options

@SushkoTech
Comment options

Answer selected by KyryloKuzyk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
FAQ
Labels
None yet
2 participants