• Unity
  • Game slowing down and exporting certain animations

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

Hey everyone,

Currently in my project I got around 60 animations. I was wondering if there is a way to export say only 1 or 2 animations from the project?

The reason I was thinking of doing that is when I add another instance of my Spine Mecanim GameObject in scene view. The game slows down quite a lot. So I figured since I only need 2 animations I might as well try to export them separately with a different SkeletonData asset file from the original Spine Mecanim GameObject.

(If its possible to export these animations separately it would probably be the fastest thing to do right now).

I checked Spine metrics tab to see # of verbs and if it might be causing the game to slow down. Attached is a screenshot of the stats.

I checked in the stats tab in Unity and my scene has anywhere between 7k to 13k (with 1 Spine Mecanim GameObject).

Not sure what might be causing the game to slow down..

While exporting these specific animations separately so I could have a specific SkeletonData asset files for them might not really be a solution, I thought it might help make the game run faster.

I just upgraded to Unity 2019.4.15f1 and I'm using Spine 3.7 (haven't upgraded to 3.8 yet)

Thanks

Ryoshi78 написал

The reason I was thinking of doing that is when I add another instance of my Spine Mecanim GameObject in scene view. The game slows down quite a lot.

What exactly do you mean by "slows down quite a lot"? After adding the second skeleton instance, do the fps go down and constantly stay at a lower count? If so, then changing the number of animations will not affect your framerate at all. It only affects load time, and I assume that that is not what you meant by "slowing down".

From your stats the number of bones is the only value that seems pretty high, compared to e.g. the Raptor example project which uses 74 bones. Nevertheless, this should not pose a problem yet. Do you perhaps use multiple atlas pages and require a lot of drawcalls (you can have a look at the Materials section at the SkeletonMecanim GameObject)?

Harald написал

What exactly do you mean by "slows down quite a lot"? After adding the second skeleton instance, do the fps go down and constantly stay at a lower count? If so, then changing the number of animations will not affect your framerate at all. It only affects load time, and I assume that that is not what you meant by "slowing down".

Yeah sorry I wasn't clear on that because previously both the loading time and fps were going down. At the moment though it seems that only the loading time is getting affected. The fps is not affected and its staying constant around 60.

At the moment I exported the desired animations as png files and it seems to have improved the loading time. Though currently Spine exported 133 images as pngs and I only have 8 key frames. Is it possible to only export the key frames and let Unity handle the in betweens?

Harald написал

From your stats the number of bones is the only value that seems pretty high, compared to e.g. the Raptor example project which uses 74 bones. Nevertheless, this should not pose a problem yet. Do you perhaps use multiple atlas pages and require a lot of drawcalls (you can have a look at the Materials section at the SkeletonMecanim GameObject)?

Yes I do, I have 4 materials using 4 different textures. 3 textures are 2048 x 2048 and one 2048 x 1024. The Skeleton data asset is handling 4 different character skins.
Could the multiple textures size be whats affecting the load time?

Lastly, the material section appears to be flickering (expanding/shrinking when I select my Spine GameObject, though if I click out side of Unity the flickering stops. Could this happen because I'm using Unity 2019.4.15f1 and Spine-Unity runtime v3.7 ?

Sorry this is the first project I'm using Spine in so I was unsure of a few things 🙂

Ryoshi78 написал

At the moment I exported the desired animations as png files and it seems to have improved the loading time. Though currently Spine exported 133 images as pngs and I only have 8 key frames. Is it possible to only export the key frames and let Unity handle the in betweens?

You should not export your skeletal animation as an image sequence for use in Unity, you cannot simply let Unity draw in-between frames. (At least not without any special machine-learning/AI driven painter-monkeys 😉 )

So please change export mode back to exporting data, and then choose binary, not json.

Ryoshi78 написал

Yes I do, I have 4 materials using 4 different textures. 3 textures are 2048 x 2048 and one 2048 x 1024. The Skeleton data asset is handling 4 different character skins.
Could the multiple textures size be whats affecting the load time?

If you are now talking about exported png image sequence, please change to export to data export as mentioned above.

Different texture sizes don't matter. What matters is the number of material changes and draw calls that are necessary, please see this documentation page entry for a detailled explanation:
spine-unity Runtime Documentation: Materials

Ryoshi78 написал

Lastly, the material section appears to be flickering

This is also explained in the above Materials section of the documentation pages.

Ryoshi78 написал

Sorry this is the first project I'm using Spine in so I was unsure of a few things

Please have a look at the documentation pages then, it covers many important aspects:
spine-unity Runtime Documentation: Getting Started

If your problems still persist after exporting the project as binary, please show us some screenshots showing your project's bone structure, perhaps something can be simplified there.

Also general optimization rules apply, you should in general not instantiate GameObjects in the middle of gameplay, but instead pre-load as much as possible at level-start (or whenever more suitable) and/or keep a pool of objects. Loading a skeleton for the first time will lead to loading the data from the binary/json file. The first instance counts here, subsequent instances don't load skeleton data again.

Harald написал

You should not export your skeletal animation as an image sequence for use in Unity, you cannot simply let Unity draw in-between frames. (At least not without any special machine-learning/AI driven painter-monkeys )

So please change export mode back to exporting data, and then choose binary, not json.

Yeah thats true 🙂 , I exported using binary and the issue does not seem to persist.

Harald написал

Different texture sizes don't matter. What matters is the number of material changes and draw calls that are necessary, please see this documentation page entry for a detailled explanation:

Yep, I think this was the problem. I got 30 elements in my materials array..

Ryoshi78 написал

Also general optimization rules apply, you should in general not instantiate GameObjects in the middle of gameplay, but instead pre-load as much as possible at level-start (or whenever more suitable) and/or keep a pool of objects. Loading a skeleton for the first time will lead to loading the data from the binary/json file. The first instance counts here, subsequent instances don't load skeleton data again.

Yeah I'm only instantiating at the beginning of the game, the only exception is respawning the player.

Checking the documentation, I opened the Dragon example scene. It currently has 12 elements in the material array.
In terms of best practices is there limit/range that I should keep in mind for mobile game development?
I understand it depends on a lot of things like complexity of the animation and target device.
As I understand, the draw call limit of mobile devices is around 50 to 100 (for newer devices).

Ryoshi78 написал

Yep, I think this was the problem. I got 30 elements in my materials array..

This would explain it better. How many atlas pages does your skeleton use (the number of png files exported)? You could perhaps group your attachments to the atlas pages much better, so that atlas pages are not always drawn in an interleaved order like A B A B A B but AAA BBB instead (as shown in the documentation pages). Alternatively, you could reduce the number of atlas pages by making attachment sizes smaller (e.g. half resolution), or allow the atlas page size to be larger (double the size). Without seeing any screenshots we have a hard time suggesting anything specific though.

Ryoshi78 написал

Checking the documentation, I opened the Dragon example scene. It currently has 12 elements in the material array.
In terms of best practices is there limit/range that I should keep in mind for mobile game development?

Metrics - Spine User Guide: Performance
It completely depends on your game setup and on the target device, we can only recommend to keep all values of your metrics at minimum. You can have a look at the example projects that come with Spine such as Spineboy, Raptor, Mix-and-match. If the complexity of your character is similar to one of the assets, then you can have a look whether your stats are in the same range or not.

The dragon example shows 12 draw calls from only 2 alternating atlas page textures as an "avoid this" example. It could be reduced to 2 or 3 draw calls by grouping attachments better to the atlas pages.

Ultimately, it comes down to measuring the actual framerate on your target devices with your desired scene setup, using placeholder assets with similar stats for testing.