Hello Guest

Author Topic: tk2dSpriteAnimator.LateUpdate()  (Read 3840 times)

Thyran

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
tk2dSpriteAnimator.LateUpdate()
« on: September 17, 2014, 03:07:05 pm »
Hey :)

I have a question regarding the performance of the "tk2DSpriteAnimator.LateUpdate()" function. My game is experiencing considerable lag at times, and when viewing it through the Profiler, the biggest culprit is tk2dSpriteAnimator.LateUpdate(). For a single frame in one of the worst instances, it is getting 585 calls and its Time is 35.68ms.

In the game, I have "obstacles" that are made up of 2 tk2dSprites and 2 tk2dClippedSprites, each with the same animator (though I'm using 2 different clips for the 4 objects). These objects are rings with a background and border. The player object passes through the rings, so I needed to use two objects to create the back background & border, and then 2 more objects to create the front mask background & border. There is a parent empty game object for each obstacle that contains the 4 children. The parent game object has a box collider, but none of the 4 animating children do.

The reason why I'm separating the background and borders into separate objects is so I can change their colors independently (I'm using 9 colors total). I could simply create assets for each color, but then that would multiply the assets 9x, and then I'd have to have 9 animations instead of 1, so I figured it was more efficient having more game objects.

Anyways, that's my set up. I have 100 of these obstacles total in the scene, but at any given time only 4-8 are present on screen. I tried creating a script that would run through all the obstacles in a foreach loop every second that disables any objects left or right of the screen, but it creates a noticeable stutter each time that Coroutine runs.

Any tips to optimize this? Not sure if I'm approaching this problem the wrong way.

Thanks!
« Last Edit: September 17, 2014, 03:14:48 pm by Thyran »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSpriteAnimator.LateUpdate()
« Reply #1 on: September 18, 2014, 10:17:22 am »
Do you turn off the ones that are off screen? You dont need a coroutine to turn it off out of screen bounds - look at the tilemap sample, tk2dTileMapDemoCoin - it enables and disables the animator OnBecameVisible / Invisible.

Thyran

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: tk2dSpriteAnimator.LateUpdate()
« Reply #2 on: September 24, 2014, 10:09:04 pm »
Great, thanks so much! Looked at the sample. Thanks again!