Hi guys, anyone have a solution to optimize this problems? I've had enclosed my profiler dectect peak of CPU when i run game. thanks for any solution you have
Posts: 1


When you instantiate a SkeletonAnimation, it always needs time to instantiate a new Skeleton and AnimationState object and all the related buffers needed to render the skeleton.
If its SkeletonData wasn't loaded yet, SkeletonAnimation's Initialize would also initialize SkeletonDataAsset, which loads the data from your Spine export. If it's from json, it will be slower than from skeleton binary. But json is beneficial for tracking changes and compatibility during development.
You can pre-load the skeleton data at your game's load time by calling skeletonDataAsset.GetSkeletonData(true) yourself in your game's loading phase. Just ignore the return value. The SkeletonDataAsset will cache it for when it's needed.

If you intend to use multiple of the same SkeletonAnimation, using an object pool in Unity will be beneficial instead of instantiating new GameObjects on the fly.
User avatar

Posts: 4942

Return to Unity