Unity 2D - Animation drops FPS dramatically - unity3d

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.

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.

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.

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.

Related

How do I efficiently render a pixelated line?

I am working in Unity2D and have a character who can shoot in all directions. The game has mobile controls and the player will choose his shooting direction with a joystick on the right side.After testing I found it rather difficult to correctly determin where the shot is going to land at. To convey this to the player I wanted to add a sort of "shooting line of sight" to the player. It is moving around the player according to the joysticks position. (As seen in the picture)
Because I want the line to be pixelated (to match the design theme of the game) I cant use the standard LineRenderer component as it doesn't support such pixelated lines. So I started looking for solutions to this problem and stumbled upon Bresenham's line algorithm. After implementing it into the game I knew which x, y coordinates I had to fill with a pixel. Currently every single white pixel in this line is a GameObject with its own SpriteRenderer and a single white pixel as a sprite. In my test scenario up to 400 pixels where rendered at once. I am already using an object pooling system to minimize the performance drag. Moving this line around drops me from around 1100 Fps down to like 200 Fps in the editor. I know it will be slightly better in the build game but I am sure it will take a toll on older mobile devices when enemys, animations etc. are present in the level.
So my question is: Is there a better or more efficient way to render the sprites? Or (preferably) do you have a better idea on how to render this line at all without creating ~300+ GameObjects. (e.g. Shaders (Zero experience), drawing on a texture)
I am grateful for any ideas that lead me into the right direction.

How to deal with low amount of animation frames on a high FPS game

Simply put: I am working on a 2d Platformer which runs with 80+ fps. I used to use a sprite sheet witch character which has a running animation with 20 pictures (frames) in total. Now I found a collection of characters which looks great but their running animations are about 9 pictures/frames and the gameplay looks super sloppy because of this. I was wondering do you know a way in which I can fake this and make this low frames looks better?

Change Unity terrain resolution without losing the terrain

I have a really complex terrain in Unity, its full of trees, grass, flowers etc.
When I run the game, the frame rate is really low, maybe 1 to 3 fps.
I read some where that the terrain resolution may be the problem since i got it cranked up high.
When I try to lower the terrain resolution, unity erases the whole terrain, which is bad since I can go spending two months to remake it all over again.
Does anybody know of a way to change the resolution of the terrain, and other terrain parameters without losing the whole terrain?
Maybe there is a script in the unity asset store that can export the terrain and lower the resolution, and re-import it, or something like that?
Anybody know of script or method to do that? I don't have time to develop a script myself, or spend huge amount of time on this.
I know one thing you can do is decreasing the resolution of the texture you used for terrain and grasees or trees on it.
What you are trying to do is very complex and will take a lot of time. An alternative way of getting higher FPS is to select all your non-moving objects, or just the prefabs in your prefabs folder and check Static in the right-hand corner of the inspector. This will boost your FPS but if you have a day-night cycle you should uncheck Lightmap Static by pressing the downwards arrow next to the Static button in the inspector.

unity2d what the different between sprite sheet and sprite packer?

What I mean different is inefficient when the game runs.
sprite sheet:
put multiple files in one texture file, and import it to unity, I only import one texture.
sprite packer:
import multiple files in unity, then use the sprite packer to pack it into one texture.
So what is the difference between them? which one is better for sprite animation?
thank you!
In terms of frame rate you will have little to no effect. However in terms of memory, you may see an effect because the sprite packer will be able to deal better with animations that have flexible size.
With sprite sheets, Im assuming you mean atlases that are made up of fixed sized cells. There is no problem with this approach, unless your animation varies dramatically in size, making it necessary to increase the overall cell size to cover the area of the largest animation frame. You would end up having huge amounts of 'empty' and thus wasted space. This is bad since on mobile memory will be your problem.
In general sprite sheets are ok for animations that fit into an efficient cell size, like animated characters:
With the unity sprite packer you wont have this problem, since it will 'pack' the wasted empty space together and create an optimal atlas, hence the name 'packer'.
You can see that in the documentation:
The explosion (or whatever it is) is clearly using optimal space. In a sprite sheet, you would be having to create cells the size of the largest explosion.
In terms of programming ease, using sprite packer you may have to add a bit of code to correct for the original sprite size, so the animation will run smoothly at the 'anchor point'. With sprite sheets, you avoid this by having the fixed cell size.

Sprites for iOS devices

I'm trying to do a little research for my next game that I'm planning to make and just wondering if anyone could give me a little direction.
I'd like to use sprites to show animation, characters walking and such so my question is this. What game engine handles sprites the best?
And how many sprites can be shown per second? Say i had a character walking and wanted it to look pretty fluid, might i be able to get 60fps? or is that way way to high?
Last question.. sorry! If a sprite has more colors and complexity, but is the same file size as something simpler would it take more processing power to display the complex one?
thanks!
James.
I would highly recommend cocos2d for sprite animations. It's very easy to pick up if you already know objective-c. And it's great for working with sprites. The animations are very fluid and when your testing your applications in an iOS simulator, it tells you the frames per second in the bottom left hand corner. The frames per second usually runs at about 60. And regarding the sprite file size, I believe if the file size is the same between two sprites then they require the same amount of processing power.
A good engine to use for it's simplicity is the Sparrow engine for sprites, sound and other things. There is no reason you can't get 60fps. As for your last question, it wouldn't make a difference.