3

I created a 2D sprite animation using the 2d animation package and the 2D Ik package. My character is one sprite sheet (PBS file). In the PBS file all the spites (eyes, mouth, etc, - character is basically a square with a face) are arranged and bones are attached. Then I animated the character's idle animation in Unity.

The animation is complex and is a total of 1028 frames (about 17 seconds).

The scene is almost empty otherwise. There are a few sprites with colliders and rigid bodies for simple platforms. There is a background image which is 1024 px. x 1024 px.

In play mode the FPS drops down to around 30 FPS (and under).

I have another scene without the animation but with a HUGE number of assets (for a 2D scene hundreds of sprites and many of them constantly in motion). This scene runs at 210++ FPS consistently.

Why does this one animation kill the FPS? I'm just getting started with creating animation for all the characters. If I add similar animations to NPCs in the scene (enemies) then this thing will probably not function at all.

Any suggestions are appreciated.

enter image description here

Zephyr
  • 11,891
  • 53
  • 45
  • 80
FatMunkey
  • 51
  • 1
  • 6
  • Open Unity Profiler and see what takes more cpu time during the gameplay. – VisDesign Jul 19 '20 at 17:51
  • The profiler show that the animation is taking up most the CPu resourse and second place is vsync – FatMunkey Jul 19 '20 at 20:12
  • Can you show us a picture of it? – VisDesign Jul 19 '20 at 20:13
  • Added a link of the image for the profiler. BTW, I have been thinking of buying Spine. would that provide better performance? Maybe export the Spine keyframes as a sprite sheet or sprite atlas? – FatMunkey Jul 19 '20 at 20:51
  • To me it seems the script is causing it. I dont know maybe the blue color does interfere. – VisDesign Jul 19 '20 at 21:01
  • Seems odd that the script would cause this in a simple scene but not in a completed scene. I'm using corgi engine so maybe some script from that is the problem. I have really zero experience with the profiler. I wwonder hich script is causeing the problem? How to fix.... – FatMunkey Jul 19 '20 at 21:05
  • Are these 2D Animations? I never used some animation engine myself im sorry. – VisDesign Jul 19 '20 at 21:09
  • Yes 2D. The picture of the profiler shows the character I animated. His eyes move and his teeth. The name George above his head, his body and the arrow are also in motion - swaying in an idle pose. – FatMunkey Jul 19 '20 at 21:22
  • Whats really odd is that I just now deleted about 75% of the keyframes. Still at below 35 FPS – FatMunkey Jul 19 '20 at 21:24
  • Its not the frames for sure. Its some script you have there. Try to shut the animations off and see if it still happens. – VisDesign Jul 19 '20 at 21:43
  • So I removed the animation and the FPS goes up to 80++. I put the animation back and did a test build. The built game ran at a 130+. I can only imagine it would be better with the animation off. I'm starting to think it's an issue with too many transparencies in the animation. The character is transparent (see the picture) so every frame it's causing an overdraw situation in the animation. Not sure how to fix that except to make the character opaque - but that destroys my concept for the game. – FatMunkey Jul 19 '20 at 22:36
  • Try to make the animations yourself without this framework. It is not that hard ans see if the numbers are better. Transparency it should not be a problem in my opinion. I think some script causes that. – VisDesign Jul 19 '20 at 22:38
  • I made the animations without the framework. The framework is simply a bunch of scripts for character control, level transitions, etc. So I guess I will send a screenshot of the profiler to the corgi engine developer. Maybe he will have some idea about the script. – FatMunkey Jul 19 '20 at 22:42
  • Do you have just one animation clip? Animation clips should be small and you switch between them either with states or blend trees. – VisDesign Jul 19 '20 at 22:44
  • It's the first one I made for the game. So, yeah, just one clip right now. – FatMunkey Jul 19 '20 at 22:45
  • It it is just for intoduction some kind of a movie just dont use animations. Bake the movie and show it. For cinematic and movement small animations and transitions do the job just fine. – VisDesign Jul 19 '20 at 22:47
  • It's the animation of the character - the idle animation. I reduced it from 17 seconds down to 5 and still no joy. – FatMunkey Jul 19 '20 at 22:49
  • Ok try to shutdown the movement or put your animated character in a fresh scene and watch the numbers it is definitely not the animation. – VisDesign Jul 19 '20 at 22:52
  • As i mentioned above, it runs fine without the animation. The script might be part of the issue. But the animation is having the negative effect i noticed. Without animation - 130+ FPS, With the animation 30- FPS. Weirdly, when i run the test build it goes up to the 130+ again. – FatMunkey Jul 19 '20 at 22:56
  • Just try it on a new scene with just idle clip without any scripts. – VisDesign Jul 19 '20 at 22:59
  • @el6976 - I answered the question myself. and thanks for the down vote...if that was you. I can't imagine what anyone thought i did wrong in my question. I did a ton of work on my own and i eventually solved the issue myself - no thanks to anyone on stack exchange! – FatMunkey Jul 24 '20 at 05:56

3 Answers3

5

For anyone having the same issue, make sure you have Burst and Collections packages installed (via the Package manager), it extremely improves the performance of 2D Animation.

tiekto
  • 51
  • 1
  • 2
  • it is indeed that Burst improves a lot for this particular issue, my FPS boosted from 40 to 100, however, where is the "Collections" you have mentioned? couldn't find it in package manager – Joe Lu Nov 04 '20 at 09:06
  • You should be able to find it via the package manager - just don't forget to enable the "Show preview packages" option under the "Advanced" button, as the package is still in preview. – tiekto Nov 05 '20 at 10:11
  • tks @tiekto, I did enable the preview but still couldn't find the collection, or mathmatic, I'm using 2020 version – Joe Lu Nov 05 '20 at 17:18
  • Ahh, I do use 2019.4 at the moment, however, I remember there was a specific 2020 version in which package manager had issues loading some packages. So I'd suggest updating to the latest stream version if that's not the case already. If that doesn't help, best solution would be to file a bug via the Editor, the support team is very fast and really helpful. Also - check if you don't already have these packages as a dependency with the existing ones. – tiekto Nov 06 '20 at 20:32
  • For those who using unity 2020 or higher and wonder where the Collection package is, just install Jobs package instead, [Collection is include in Jobs](https://forum.unity.com/threads/where-is-the-collections-package-in-unity-2020.967006/) – Mr. For Example Aug 23 '21 at 11:36
1

So I spent a couple of days this week and created sprite sheet animations to replace the skeletal animation I made in Unity. As I suspected, the performance is light years ahead. I have MORE animations now and some of them are as long as 270 frames. Yet I consistently see greater than 220 FPS. It's too bad that unity's 2D animattion package is so slow. To accomplish the same animation I was looking for, I ended up rigging and animating my character in Blender 2.8 using Andreas Esau's COA Tool (Cut-Out-Animation Tools) Add-On.

COA Tools is an awesome tool but I wish it could export a rendered sprite sheet to Unity. I ended up exporting each frame as a separate image and using TexturePacker to make the 2048px square sprite sheets I needed. Once I got the sprite Sheets into unity I was able to quickly set up animation clips and test it out.

As I said, the sprite sheets are far and away better than animation created directly in Unity.

If you bothered to read all the comments on my original post, I will say that there are a lot of scripts running and a lot of computation happening. It is there in the profiler for sure. But this was definately not the main culprit for taking down the FPS. It was absolutely the animations.

FatMunkey
  • 51
  • 1
  • 6
  • Are you confident you did use the skeleton animation correctly? How fine was the triangle mesh used for animating? That is a huge factor in performance. Also keep in mind with frame by frame exporting you have now exchanged ingame performance at cost of massively more memory requirement. – AlexGeorg Jul 30 '20 at 13:06
0

Looking at your profiler screenshot, SpriteSkin.LateUpdate() takes a large chunk of your frame time. To reduce the amount of time CPU spends on deformation, you can limit the number of vertices in that are used for each Sprite Part - you can adjust it in the Skinning Editor with Edit Geometry tool. Basically, the less the amount of vertices the better the performance.

Also, make sure that each Sprite Skin component has the Enable Batching option enabled. This will enable Burst and Collections packages to speed up calculations. For more details, checkout this 2D Animation documentation.

Recently, Unity a free ebook was released that covers in details best practices and how to prepare art for 2D animation. You can find it here.

Marunia
  • 1
  • 1
  • 1