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

Поделиться
HTML-код
  • Опубликовано: 18 дек 2024

Комментарии • 74

  • @lastsipahi
    @lastsipahi 2 месяца назад +1

    This technique really works well, thank you. Your code however generates a scriptable object with assets in it and sadly (probably a editor bug) it breaks time to time. But I got the general idea and wrote my own script. Now I can animated and move 1000+ enemies with dots! Thank you again!

  • @andrewallbright
    @andrewallbright 2 года назад +5

    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.

  • @poobagification
    @poobagification 2 года назад +3

    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 .

  • @newbieproable
    @newbieproable 2 года назад +1

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

  • @Betruet
    @Betruet 2 года назад +1

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

  • @skave7228
    @skave7228 11 месяцев назад +2

    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?

  • @woodsmanthepeasant
    @woodsmanthepeasant 2 года назад +3

    Really great video. Looking forward to more!

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      Thank you 🙏. You really helped me on this topic with your video!

  • @CronoBJS
    @CronoBJS 7 месяцев назад +2

    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!

    • @LlamAcademy
      @LlamAcademy  7 месяцев назад +1

      That’s awesome to hear! Thanks for sharing!

  • @durvids474
    @durvids474 2 года назад +1

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

  • @GilbertLovesCats
    @GilbertLovesCats Год назад +1

    Wow I need this thank you!

  • @geri4367
    @geri4367 2 года назад +2

    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 :)

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      Hmm good question. I will have to try that out!

    • @PrzygodazUnity
      @PrzygodazUnity Год назад

      @@LlamAcademy Did you try it ? :D

  • @AletseDev
    @AletseDev 2 года назад +1

    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.

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      Absolutely! They’re a little tricky topics to cover because each game has different factors and performance considerations and constraints, but optimization techniques are not very well covered!

    • @litjellyfish
      @litjellyfish 2 года назад

      First question. How much have you profiled it? What / where are the current / foreseen bottlenecks?

    • @LlamAcademy
      @LlamAcademy  2 года назад

      I talk about those in the video. The performance is really great even when not using a “Manager” (I.e. using ~800 update calls). Memory and not being very flexible in terms of Animation playback are the two big drawbacks

  • @taavetmalkov3295
    @taavetmalkov3295 8 месяцев назад

    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?

    • @LlamAcademy
      @LlamAcademy  8 месяцев назад +1

      Sure. Billboards / 2d is always more performant because it's extremely low poly and simple lighting

  • @neilfosteronly
    @neilfosteronly Год назад

    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.

    • @LlamAcademy
      @LlamAcademy  Год назад +1

      Remember to bake with the Skinned Mesh Renderer and view with the Mesh Renderer. Sometimes I had to bake it twice to get it to start showing up, not sure where that came from.

    • @neilfosteronly
      @neilfosteronly Год назад

      @@LlamAcademy Ok, I think I baked on the parent level and it had the animator but not the skin mesh. Why I had to add a mesh filter. Thanks for the videos.

  • @truedreams5187
    @truedreams5187 9 месяцев назад

    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 ?

    • @LlamAcademy
      @LlamAcademy  9 месяцев назад

      If you have simple transitions from one state to the next, they will be baked as well. HOWEVER it is important that the order in which you play them back to bake will determine the blend. If you have 3 states (A,B,C) that can go to 1 other state (D), the D animations will have the transition from whichever state you transitioned to D from. Let’s say you did C->D. Any time you play D it will include the transition from C to D.

    • @truedreams5187
      @truedreams5187 9 месяцев назад

      @@LlamAcademy Got it. Would be more better if you could make a tutorial about it.
      As transitions are mostly used in animator and if we could optimise that than its great!

  • @alissonalencar7154
    @alissonalencar7154 7 месяцев назад

    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?

    • @LlamAcademy
      @LlamAcademy  7 месяцев назад

      I don't think this works for 2D, but I've never worked on a 2D game.

  • @abulak3477
    @abulak3477 Год назад

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

    • @LlamAcademy
      @LlamAcademy  Год назад

      I know of them as a concept and want to get to making a tutorial on how we can bake animations into a texture and then play them back. I just haven't had enough time to dive into the topic to make that video yet.

  • @truedreams5187
    @truedreams5187 9 месяцев назад

    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!

    • @LlamAcademy
      @LlamAcademy  9 месяцев назад

      I didn’t keep up with all the App Store and google play store requirements so it has been taken down, but there’s a link to the site with some screenshots and game play in the description. I’ve described the setup performance in another comment here

    • @truedreams5187
      @truedreams5187 9 месяцев назад

      @@LlamAcademy Got it

  • @TheMADmk
    @TheMADmk Год назад +1

    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.

    • @LlamAcademy
      @LlamAcademy  Год назад +1

      Yeah, that is a good idea for you to save mesh memory performance and also some rendering performance!
      I think you'd have to bake the animations with lower poly meshes and at different FPS counts then based on squared distance to the camera playback at the different FPS speed.
      I thought about implementing that, but ended up needing to have the draw call batching because the lower end mobile devices couldn't handle the animations even though the midrange ones I was testing on were fine.

  • @raymondf200
    @raymondf200 Год назад +1

    love this thanks

  • @ericgardiner7715
    @ericgardiner7715 10 месяцев назад

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

    • @LlamAcademy
      @LlamAcademy  10 месяцев назад

      I used this in my mobile game in 2021/2 and did not encounter memory issues. I had about 4 models (2-5k tris) with 3-5 animations at anywhere from 30-120 frames each.
      On mid-range phones such as Pixel 3a it ran quite well and did not have RAM limitations. On very low end devices it was still GPU bound before RAM-bound.
      Edit: on iPhones as old as iPhone 7 it performed exceptionally well.

    • @ericgardiner7715
      @ericgardiner7715 10 месяцев назад

      @@LlamAcademy Thanks! 🙏

  • @The-Filter
    @The-Filter Год назад +1

    Using the latest 2021 LTS your project gives an error that says "The Type or namespace name "EditorCoroutines" doesn' exist!" :(

    • @LlamAcademy
      @LlamAcademy  Год назад +3

      Make sure you have imported the EditorCoroutines package from the Package Manager!

  • @danlodosgames
    @danlodosgames 2 года назад

    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?

    • @LlamAcademy
      @LlamAcademy  2 года назад

      If you do a "dry run" do you see your animated model perform that animation? It may be an issue with not having the right GameObject selected, doing it on a prefab in the Project Panel, or something like that. If "Dry Run" shows you what you expect to see, you should get the right meshes baked.

    • @danlodosgames
      @danlodosgames 2 года назад

      @@LlamAcademy yes, with "dry run" option, model play her animation.
      In general, I understand correctly that this will not work with the MeshRenderer on a geometrically simple model?

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      It should bake no problem on any skinned mesh renderer and replace it with a simple MeshRenderer. If you have a simple reproduction example you could send me I could take a look at it. If they’re shareable models and animations, send me a repo on GitHub. Otherwise you can send me a small example project to support@llama.software and I can see if I can see what’s going on

  • @chovatiyahimanshu9135
    @chovatiyahimanshu9135 2 года назад

    What about animation instacing is mesh animation is faster in performance then animation instacing Or not?

    • @LlamAcademy
      @LlamAcademy  2 года назад +2

      I would say, generally speaking, Animation Instancing has the potential to be even faster than this method. So far, I haven't been able to make the Unity-provided Animation Instancing work for me, that's one of the reasons why I implemented this into my game.
      You could potentially do some extra lifting on top of this to use Graphics.DrawMeshInstanced to lower the draw calls here to maybe improve performance even more. At that point it would be an interesting exercise to compare which would be faster

    • @chovatiyahimanshu9135
      @chovatiyahimanshu9135 2 года назад

      @@LlamAcademy thanks you for replying I will check both methods 😊

  • @ibrahimokur4169
    @ibrahimokur4169 Год назад +1

    Man i love you so much

  • @paulorodriguez6288
    @paulorodriguez6288 2 года назад

    i can't believe this method performs better than the default animation system, really feels like it shouldn't.

    • @LlamAcademy
      @LlamAcademy  2 года назад

      It is a little surprising at first glance, but remember the optimization here is removing almost all CPU calculations for the animation. At runtime the SMR Animator has to compute where all the vertices will be and update those all on the CPU.
      Here we’re just removing that and swapping what we send to the GPU to render every couple of frames. It’s not perfect for all scenarios, but it works pretty well for some!

    • @litjellyfish
      @litjellyfish 2 года назад

      Can you not implement skimning in the GPU? Or in-areas of storting different meshes just store vertex delta? Like Classic mesh morphing. As its just add/sub it should perform at lot quicker than skeleton skinning. Also probably you can just store some key frames and blend between the other. Which with less data allow you to store more data and even perform kind of blending.
      It’s not going to be as fast as just swapping mesh but should be quicker I guess than the skinning. At least if it’s possible to implement this in C++ and extend that to Unity. Not sure if that is possible or if you only can use C# as I don’t really know Unity.
      Also for smaller animations like this you can even store this as textures and use compute shaders to allow the GPU to calculate this

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      Absolutely! One thing I may look into is doing this via a compute shader to see if it’s worthwhile or could improve memory usage. Right now this was “good enough” for my game so I thought I’d share it. The concept you are describing is actually what I was using before in the way of the Mesh Animator Unity asset, but that didn’t work for me on URP so I needed something to help out the performance when I didn’t want to write custom shaders.

  • @INeatFreak
    @INeatFreak 2 года назад +1

    Saving hundreds of meshes? It's a bad idea. what happens when you add clothing or armor to the character? or change the character entirely?
    It is not scalable and there are way better ways of doing this like storing the animation vertex positions over time in a texture.
    Here's a video explanation of the concept made in blender but you can find one for unity as well if you search for it: ruclips.net/video/NQ5Dllbxbz4/видео.html

    • @LlamAcademy
      @LlamAcademy  2 года назад

      All valid points. As I said in the video, this is not applicable for every use case and does use quite a bit of memory. There are alternatives that fit other use cases like you described. In no way is this video selling this method as the silver bullet for optimization of animated meshes 😅

    • @litjellyfish
      @litjellyfish 2 года назад

      Yea that was my thought also to do mesh blending which would be a bit more flexible

    • @Haxel0rd
      @Haxel0rd Год назад

      @INeatFreak there are use cases where this method is a live saviour, because other methods may not work in a particular case. In my case for example i dont need clothing or other stuff.

  • @TREXYT
    @TREXYT 8 месяцев назад

    Hi, can we use it for static object culling ? The idea is to split any static object to multiple parts this way we can use object culling on big objects (exemple a big tree), if you know other way without using 3rd party software please let me know, thanks

    • @LlamAcademy
      @LlamAcademy  8 месяцев назад

      I think you may want the HLOD system (tutorial: ruclips.net/video/f6KaJHUfE2M/видео.html github: github.com/Unity-Technologies/HLODSystem ). This video only about animating models.

    • @TREXYT
      @TREXYT 8 месяцев назад

      @@LlamAcademy yes i know that not the use case of your project. hlod system project looks like removed from github link that you sent me, any way to get it ?

    • @TREXYT
      @TREXYT 8 месяцев назад

      @@LlamAcademy i found correct link i will check it, thanks

  • @dibaterman
    @dibaterman 2 года назад

    I think I'm starting to lose my mind, I got something akin of a naughty pleasure seeing how sexy that code looked. I need to go look at some grass or something, been coding like 16 hours a day for the last 5 months.

    • @LlamAcademy
      @LlamAcademy  2 года назад

      😅 you might need to take a break!

  • @Syper7
    @Syper7 8 месяцев назад

    Me trying to do this in an out dated version of unity 😅

  • @MrMaaz909ByMeshStudio
    @MrMaaz909ByMeshStudio Год назад

    We can use animation bake shader it is better then this I think @Llam

    • @LlamAcademy
      @LlamAcademy  Год назад

      Yes you can and it should give you better performance. This is an alternative to that in cases where you don't want to deal with that style of a shader.

  • @dudley0007
    @dudley0007 Год назад

    👊