Hello Guest

Author Topic: Lagging frame  (Read 5019 times)

Nikita

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Lagging frame
« on: June 27, 2013, 04:15:38 pm »
Hello!
I have 5 or more animation and they have all same fps 10 and frame count 6. The problem is that they don't play synchronously and some frame may be lag. All animation synchronied by one animation animi_main by trigger on the last frame this animation. Below table of how it is. All animation have toggle play automatic equal true on start game.

frame number anim_main anim_1 anim_2
0                     0               0           0
1                     0               1           1
2                     1               1           1
3                     1               2           2
4                     2               2           2
How is it fix? Please, help, i can't understand what's wrong.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Lagging frame
« Reply #1 on: June 27, 2013, 10:54:35 pm »
I don't think I understand the issue.
How do you play the animation? Is this right?

At the last frame of an animation, from anim_main, you call
 anim_main.Play('...")
 anim_1.Play('...")
 anim_2.Play('...")
Is that correct?

If so, the behaviour is more or less undefined. Remember in Unity there is no order of update functions, so lets say anim_main.Update happens BEFORE anim_1 and 2. Then from anim_main.Update, where the animation event gets triggered, you call Play on _main, _1 and _2. So now update happens on _1 and _2, and they are now one frame ahead of _main.

I hope that makes sense - you will have to deal with this kind of sequencing at some point or other when making a Unity game if you need ANYTHING sequenced precisely. There are many ways to work around this, you will have to try something like this - from the event, create a coroutine. Coroutines run at the end of the frame after EVERYTHING, after all the Update functions, so you will have a synchronised play.

http://docs.unity3d.com/Documentation/Manual/ExecutionOrder.html
for more info.

Nikita

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Lagging frame
« Reply #2 on: June 28, 2013, 01:14:36 pm »
Yes, it is correct.  I make play by this and all work correct! Thanks a lot!
   IEnumerator Play(string ClipName)
   {
      yield return new WaitForSeconds(0.0f);
      RefAnimSprite.Play(ClipName);
   }