Bake Your Animations to Greatly Improve Performance...For Some Use Cases | Unity Tutorial

preview_player
Показать описание
In this Unity tutorial you will learn how to bake animations as a series of "snapshots" of meshes. These snapshots can be taken at a configurable framerate that suits your game.

It also does not reduce the Draw Calls, as Animation Instancing will do. Instead, this approaches the problem by resolving the "CPU Skinning" taking up a lot of CPU time on the main Unity thread to improve FPS.

Strangely, with my initial attempt, the performance was actually worse than what is implemented here. I didn't have time to dive into that and the performance here was "good enough" for my use case.

💸 Ongoing Sales 💸

📚 Resources

📱 Let's stay connected

----

----
Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.

#unitytutorial #tutorialtuesday #gamedev #tutorial #unity #llamacademy #gamedevelopment

Chapters:
00:00 Problem Statement - SkinnedMeshRenderers at Scale.
01:01 A Solution - Precomputed or "Baked" Animations
02:55 Creating Baked Animations with an Editor Script
03:46 Bake Your Animations!
05:23 Animator Considerations when Baking
06:37 Become a Supporter!
07:03 When is this a viable option, and when is it not?
Рекомендации по теме
Комментарии
Автор

I love this! I'm working on bundling all my shader GPU instancing baking techniques into a package, but for non-GPU instancers, I'll definitely be sending them this video. Great work!

KingCeryn
Автор

This is some spicy content! I'm always a fan of optimization tuts since it's a deep subject :o

I have/had a project where I was rendering out ~250 copies of the same thing (mixamo goblin + mixamo animation). It killed my performance. My solution was to cull the animator component so that if a camera wasn't looking at the model it wouldn't animate. That and importing the model to "decimate geometry" a few times helped restore performance. Okay, I also redid the camera work so it wasn't looking at everything all at once too.

All this said I didn't even think the technique described in the video is even an option. Yes unity has components and resources but they can't predict everything -- writing custom tooling like this seems to clearly help.

andrewallbright
Автор

Really musthave idea to know for optimization! Thank you so much!

newbieproable
Автор

Love it! This is super useful, thank you so much!

durvids
Автор

Really great video. Looking forward to more!

woodsmanthepeasant
Автор

This is amazing! Thank you for your video. I tried the whole GPU Instancing and ran into so many issues, and was kinda wrecking my brain. I tried the script from the GitHub but also ran into some issues, not sure if it was a Unity Version issue but ran it through Claude 3 and ChatGPT to resolve the issues. It was able to create my Mesh and split it into all the single frames. I had to do some other Modifications to the "MeshAnimator" and im able to store an array of the Animation Clips and play them When I need to. My project went from average 45~fps to 450~fps average! It may not be as fast as GPU Instancing, but its a Hell of a lot faster than the built in "Animator" even with a bunch of Meshes on Screen at 60fps. Sure it may not be able to do the Blending of animations like the animator, but for My use case, its actually exactly what I needed!

CronoBJS
Автор

Wow this is really cool I had no idea about it. Thanks a bunch.

Betruet
Автор

Now I know the answer to the age old question "Do you even lift, bro?" The answer is yes. You do the literal and metaphorical heavy lifting for us .

poobagification
Автор

I have a problem with the Git code. In the Git project everything works fine, but as soon as I port the scripts to my own project everything lags. I understand it's because of the update of each NPC, but the logic is the same as in the Git project in wich it run smoothly. Has anyone had to deal with this problem too?

skave
Автор

so if got a billboard instead of a mesh... it would kick ass in terms of performance? i wish to do a backsmith on a greenscreen ( in multiple angles) and put those images into a camera location based billboard animation. is it reasonable thing to do?

taavetmalkov
Автор

This vid is amazing, right now im working for a indie world open game, this vid helps me a lot. Can make more videos for improving performance? i think is super interesting and i don't found any video talking about this things.

AlexisBleeding
Автор

Hi not sure if you'll see this, great video by the way and going to see if this technique works on my machine. One thought though is would this work with LOD so background meshes are playing animations with much less polygons and possibly a lower fps say 5 or even 3. Should be able to boost performance drastically. Not sure how you'd implement it, may have to do some experiments myself. All the best.

TheMADmk
Автор

hey new on unity here, does this works with 2D animations? if Yes how can i do that? I dont have the animated mesh creator.
if not, is there a way to bake the 2D animations, or some way to save performance?

alissonalencar
Автор

I watched your completed tutorials but the question is what if i have multiple animation clips which are making transition with each other. like anim.setbool("Walk", true); OR anim.setbool("Attack", true); etc.. In this case it won't be possible right to bake the whole animator controller with its transitions and its speeds ?

truedreams
Автор

Have you compared the performance of this vs the legacy Animation component that can play animation clips without the Animator logic?
I bet that would perform just as good, if not better, than this solution. But I may be wrong :)

geri
Автор

Hi, thanks for the material!
For some reason, I select the model, it generates so, but in the console I see this: "Setting MovingAnimation to have 0 meshes".
if i remove foreach loop(where SkinnedMeshRenderer, 103) and replace Physics.BakeMesh..., it works, but all meshes are empty.

Any idea what the problem is?
upd: SkinnedMeshRenderer must be present, even on a simple model?

danlodosgames
Автор

I got the basics to work on it but I never see the animations. How do you get the material to show on the mesh?
Edit: Figured it out. Have to add a Mesh Render to the gameobject. Now I see it has the correct amount of meshes for the animations but they are all the same. So no movement.

neilfosteronly
Автор

Hello could you recommend whether this is an effective solution for building to Mobile games given that it requires higher memory use?

ericgardiner
Автор

what is your game name ? link please? did you used the same approach for your mobile game ? did you used only 1 animation clip with no transitions between ? please tell in detail . It will really going to help me!

truedreams
Автор

do you know about Vertex Animation Texture? i wonder how they scale

abulak