Hello Guest

Author Topic: Big lag when an animation plays using a different collection  (Read 5042 times)

Evil-Dog

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Basically I'm working on a 2d fighting game with lots of frames for all the moves.
Everything works fine except that there's a big lag the first time a new collection is called upon by an animation
For exemple, the game starts and the character plays the  idle animation that uses sprites from the Movement collection.  As soon as I attack and it plays the attack animation using sprites from the Attacks collection, there's a big lag.  Then attacks are fine from that point.  Then if I do a special move (uses the Specials collection), another big lag.
I'm talking like 0.5-1 seconds.
It only happens the first time a collection is called into action.  Then it's like the atlases are loaded and it's all fine.
Thoughts?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Big lag when an animation plays using a different collection
« Reply #1 on: May 29, 2013, 09:07:41 am »
Thats how Unity works. It loads all textures into memory when accessed, but only uploads to VRAM when first visible. The best bet is to force Unity to load everything - you can do this in the loading screen, etc, by creating a sprite from each of these collections in the background somewhere. You can even hide it behind the splash screen - all it needs is for Unity to draw it once, and the texture will then be loaded.

MaaS

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Big lag when an animation plays using a different collection
« Reply #2 on: May 29, 2013, 12:12:33 pm »
Hmm...

Will this happen also if I'm using the "multiple atlases" check for one sprite collection? I mean... when showing a sprite that is stored on a secondary atlas, will it be loaded at that time, or if I use any sprite from the collection all the atlases will be loaded?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Big lag when an animation plays using a different collection
« Reply #3 on: May 29, 2013, 12:16:29 pm »
Textures in Unity are only uploaded to VRAM when they are drawn, so yes, it will mean that you will have to prime it somehow.
Or work around it by keeping the atlases small enough that it doesn't take forever to upload.


Evil-Dog

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Big lag when an animation plays using a different collection
« Reply #4 on: May 29, 2013, 04:30:46 pm »
Thanks! That's what I figured, that it was on unity's side.  I will do what you suggested and have them on the stage somewhere for loading purposes and then hide them.
Thanks