• Runtimes
  • Unity SkeletonAnimation.OnEnable causes lag in game

  • Изменено
Related Discussions
...

Hello,
When i initialize a game object with skeleton animation from a prefab in runtime it causes a high usage of cpu and creates a lag in game. How can i solve this? (When i look at profiler it shows %96 of cpu usage comes from SkeletonAnimation.OnEnable() )
Thanks.

It doesn't even have an OnEnable method though.

1) Are you able to check which methods deeper in the call stack it's taking a lot of time in?
2) Also, does it happen every time you Instantiate a prefab? Or just the first time (per prefab)?

If it's just the first time, it might just be json deserialization that's taking time.
Fortunately, that's something you can do with a preloader so loading can happen, say, before a level instead of when you need to spawn skeletons.

You just need to get references to all the relevant SkeletonDataAssets and call GetSkeleton on each one of them to get them to deserialize at that point.

It happens when instantiating the prefab first time later ones doesn't cause any problem. Could you please define the solve more clear.

udogames написал

It happens when instantiating the prefab first time later ones doesn't cause any problem. Could you please define the solve more clear.

How many atlas pages / how big are the textures you're using?

Also, how big is the JSON file? The JSON file is processed the first time something tries to access it then it becomes cached - if this is causing the lag then you likely must include an initial "Loading" layer to your game that processes all the json files you need for your scene first. This can be done by using GetSkeletonData( bool quiet ) on the skeleton data asset in question.

edit
Didn't read Pharan's reply, same info heh.