Search Unity

Mesh Animator - Highly efficient animated crowds. For support, please use email.

Discussion in 'Assets and Asset Store' started by jschieck, Dec 7, 2014.

  1. noahx

    noahx

    Joined:
    Nov 22, 2010
    Posts:
    77
    Hi,
    I finally made it "work" but I'm encountering a situation that I don't know how to deal with. Currently there are 3 animations (idle, walk and shoot). The idle animation is the default, so as soon as a unit/object is created, it plays that animation again and again just by placing the object in the scene. So I coded a few lines to indicate what animation to play when the unit is "shooting" his gun, so I'm calling a function that plays the animation, and I'm using this:

    public void actorattack()
    {
    meshAnimator.Play(2);
    }

    The index 2 is for the shoot animation and it plays it well but after it plays it, the unit plays no more animations, it simply stays still, even if I call the function again to "shoot again", it doesn't play it anymore. I made another function to "force" to play the idle animation and then calling again the shoot animation and this time it played it. So, I thought that after playing that animation from the index 2 it would go back to play the default "idle" animation but it is not happening. How do I do that so the unit can continue idling after shooting once and playing the shooting animation whenever it is called to do so?

    *The "Play automatically" option is set to "true" on the Mesh Animator.

    Thanks.
     
  2. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    You can use the event, MeshAnimator.OnAnimationFinished, to then play your idle after your attack. Alternatively, use PlayQueued.

    So your code would be something like

    Code (CSharp):
    1.  
    2. public void actorattack()
    3. {
    4.     meshAnimator.Play(2);  
    5. }
    6. private void Start()
    7. {
    8.     meshAnimator.OnAnimationFinished += ChooseNextAnimation;
    9. }
    10. private void ChooseNextAnimation(string anim)
    11. {
    12.     switch (anim)
    13.     {
    14.         case "attack":      
    15.             meshAnimator.Play("idle");
    16.             return;
    17.         // other stuff here
    18.     }
    19. }
    20.  
    21. // or if you don't need additional logic like above, just use this
    22. public void actorattack()
    23. {
    24.     meshAnimator.Play("attack");
    25.     meshAnimator.PlayQueued("idle");
    26. }
     
  3. Jackless

    Jackless

    Joined:
    Jan 9, 2018
    Posts:
    19
    Hello,

    first of all thanks for this great tool its amazing ;)
    But i have a curious "Problem" here. For some reason after the bake my model is so tiny in the scene that it isnt even visible from a normal distance and once i hit play it is a 100 times bigger than the normal model and yes it is exactly 100 times bigger.
    Heres a picture: upload_2018-1-11_19-10-49.png

    i have marked the normal model and to right is the baked one :D
    Do you have an idea what is causing this?
     
  4. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    This is because your model when exported from the 3D package had scaling transforms. This appears after you bake because the original SkinnedMeshRenderer has inverse scaling in it's skin weights. But when you bake you lose this information.

    To fix it, edit model in your 3D software and freeze the transformations before exporting.
     
    Jackless likes this.
  5. Jackless

    Jackless

    Joined:
    Jan 9, 2018
    Posts:
    19
    Ok thank you very much!

    One quick question though.
    I have 3 meshes of the same model for LOD. I guess its not possible to work with Unitys built in LOD if i bake all three of these seperetely?
    Is it somehow possible to bake all 3 Meshes together to work in tandem with the animation LOD somehow?
     
  6. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Actually baking them separately is how you'd have to do it. You just need to create duplicate animation files in your project because they'll overwrite each other when you bake.

    Then you set it up just like you would a traditional LOD, and it will turn off/on the 3 different mesh animators. You just have to write a custom script to sync them up when then LOD switches

    There's a post in this thread where I describe it, sorry on mobile so I can't find it at the moment
     
  7. Jackless

    Jackless

    Joined:
    Jan 9, 2018
    Posts:
    19
    ah thats awesome!
    Thank you very much for the help, i´ll find the post you mentioned ;)
     
  8. Jackless

    Jackless

    Joined:
    Jan 9, 2018
    Posts:
    19
    Hello its me again^^

    yesterday i could run a scene with more than 6000 animated models in a scene with more than 150 fps and today i cant even reach more than 3000 without going below 30 fps.
    All these models only consinst of one mesh and one material and theyre playing a simple idle animation.
    upload_2018-1-14_19-22-38.png

    Can this be caused by the animation length or by the amount of animations on the mesh which is currently 13?
    I have already set the animation compression to 0.01 and added 4 LOD levels.
     
  9. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Hmm it's hard to say what is causing the spike. Can you turn on Deep Profiling and look and see what exactly is causing the spike?
     
  10. Jackless

    Jackless

    Joined:
    Jan 9, 2018
    Posts:
    19
    upload_2018-1-14_19-53-6.png
    I also have a huge editor overhead for some reason. Should i go deeper into those methods?
     
  11. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Do you have Root Motion Mode turned on when you baked the asset? That seems to be the bulk of the processing time
     
  12. Jackless

    Jackless

    Joined:
    Jan 9, 2018
    Posts:
    19
    will check that as soon as i can although i think i had disabled the animator completely before baking
     
  13. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Well it's not something on the Animator. In the Mesh Animator bake window, there is an option for "Root Motion Mode" if you are baking a Humanoid rig type.

    upload_2018-1-14_16-1-45.png
     
  14. Jackless

    Jackless

    Joined:
    Jan 9, 2018
    Posts:
    19
    that was definitively deactivated.
    But i have just noticed that for some reason the baked animations are a lot longer than the ones of the original model.
    They are 50 to 70 frames long when I actually made them between 30 and 40 frames. Im a little bit puzzled.
     
  15. Jackless

    Jackless

    Joined:
    Jan 9, 2018
    Posts:
    19
    Seems like the problem fixed itself^^
    Everything is running fine again today without any changes by me, maybe it was my computer.
     
  16. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Is it possible to bake any mesh at runtime? I bought another asset "Obi Rope" and I would like to bake the physics into an animation. I doubt it would work, just curious.
     
  17. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    No this is not possible, sorry.
     
  18. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    83
    Is it possible to bake the same animation for different skinned meshes? I have 8 different humans to create the crowd of a stadium but when the animation of a human then all other models take the mesh of that human. I hope it's clear...
    Thanks
     
  19. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Yes but you must bake for each skinned mesh separately. The system will place the MeshAnimation object in the same folder as the original mesh, so if they all use an animation called "idle", after baking 1 of the meshes, move all the MeshAnimation files to a different folder so it's not overwritten when you bake the next mesh.

    Unfortunately mesh's cannot share animations at this time, because the mesh itself is what is stored in the bake.
     
  20. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    83
    Ok it works. Thanks
     
  21. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,300
    I tried to bake the sprinting animation of a horse. But the baked animation is moving instead of just having the animation at the model's location. Picture is below.

    I checked the animation itself with that model. The movement was in there. When I enabled "Bake Into Pose" of "Root Transform Position (XZ)" the location changes were gone. However, the baked animation still has that location change. Any idea what I need to set so that the horse sprints at the location I position it?

    Also, I found a bug:

    When you hit play while the Mesh Animator window is open, all the Bake Animations get re-selected, even though I had only 1 animation selected before I hit the Play button.

    And a wish list:

    Regarding the demo: The Performance Tester script shouldn't be on the camera.

    A random distribution script for objects would be really handy for such an asset.

    A distribution script for a grid, specify number of objects in x and y direction for quick performance testing would be nice.

    Thank you!
     

    Attached Files:

    JBR-games likes this.
  22. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    In the bake window, Root Motion Mode should be set to None. Then the animation root motion shouldn't be applied to the character during the bake.

    If it still does, email or PM me the model and I can take a closer look.
     
    JBR-games likes this.
  23. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,300
    This doesn't work because I use a Horse model and not a Humanoid. According to the doc here

    http://www.jacobschieck.com/projects/meshanimator/documentation/documentation.html

    this works only on Humanoids:

    • Root Motion Mode (beta) - If baking a humanoid prefab, this option will appear. It can be used to apply root motion to the mesh or transform.
      • None - No root motion will be applied.
      • Baked - Root motion will be baked into the mesh, but not move the transform during playback.
      • Applied To Transform - Root motion will be applied the MeshAnimator transform during playback.
     
  24. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Ah right of course... Can you send me the model and I'll figure out how to bake it or get you a fix.
     
  25. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,300
    Problem is it's an asset I purchased, so can't send it to you. Is there something I can try?
     
  26. FastTurtle222

    FastTurtle222

    Joined:
    Dec 24, 2017
    Posts:
    28
    Does this work with GPU instanced models?
     
  27. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Yes. There are a few requirements however.

    1. The materials used need to be support GPU instancing (even without Mesh Animator)
    2. Only meshes currently displaying the same frame of animation will be instanced for example
    This process happens automatically inside Unity since all it cares about is that the meshes displayed are the same and that they are using a GPU instancing supported material
     
  28. FastTurtle222

    FastTurtle222

    Joined:
    Dec 24, 2017
    Posts:
    28
    I should have been more clear, I am attempting to animate characters with the new unity ECS. The entities created do not represent a game object you can see in the hierarchy. So you use this to render the mesh. Will I be able to use your system to animate these entities?
     
  29. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Not out of the box, but you could edit the code to do it, instead of updating the MeshFilter mesh, just draw using the Graphics API. I've been working on such a system but it's not ready yet.
     
    blitzvb and JBR-games like this.
  30. FastTurtle222

    FastTurtle222

    Joined:
    Dec 24, 2017
    Posts:
    28
    Alright well one other question, how would this work with UMA? Would I be able to just bake the animation data for the base uma or would every customized uma need their own animations baked?
     
  31. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    I have not used that asset, but judging off of the store page you would need to bake each customized UMA since they'd have different meshes
     
    JBR-games likes this.
  32. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    You can swap out materials / textures on the same mesh. This may work for distant / background people.
     
  33. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,300
    How do you start the animation with a random frame? Currently I have a 1000 meshes and they all animate synchronously. I'd like to get some diversity into it.

    I noticed that in the stadium scene the meshes have a different speed. It would be nice if you could expose a random range for that in the inspector.
     
    Last edited: Mar 31, 2018
    JBR-games likes this.
  34. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    You can use the SetTimeNormalized method. So something like:
    Code (CSharp):
    1. GetComponent<MeshAnimator>().SetTimeNormalized(Random.value);
     
    JBR-games and Rowlan like this.
  35. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    It is my understanding that when I use MA to animate a character, I must use legacy animation type scripts, so I am wondering:

    1. Is there any AI asset on the Unity Asset Store that supports MA, or vice versa?
    2. Would you consider offering a separate asset that specializes in AI for MA assets?

    If I need to write scripts to drive the MA assets, this will slow my development considerably.
    Incidentally, I am already an owner and a fan of Mesh Animator.
     
  36. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    Can you explain a little bit about what your actual needs are.
    are you planning on using navmesh to move your characters around?
     
  37. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    Can you explain a little bit about what your actual needs are.
    are you planning on using navmesh to move your characters around?
     
  38. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    My application is basically an RPG style game, primarily outdoors. My Player character engages in combat with NPCs that are animated by AI. I have been experimenting with Emerald AI, which handles combat and requires NavMesh.

    There are places in my game where a couple hundred animated NPCs would look fantastic. The easiest application would be to have MA assets in the distance, playing a few animations without moving around, and have regular Emerald driven NPCs close to the Player, for interaction including combat.

    The next level of use would be MA NPCs that could locomote and animate intelligently, meaning Emerald and NavMesh. or basic obstacle avoidance.

    The highest level would be MA NPCs with hit boxes driven by AI that can take and deliver damage.
    I'm trying to determine how deep I can safely wade into MA before the complexity of the code etc. overwhelms me. I have been successful with Unity up to this point, by not asking assets to do much more than they are capable right out of the box.
     
  39. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    The only difference between a baked MA mesh and traditional Animator is the script you call to play the animations. Everything else functions like any other gameObject would. A lot of the Legacy Animation component methods match 1:1 with MeshAnimator methods.
     
    wood333 likes this.
  40. HenryChinaski

    HenryChinaski

    Joined:
    Jul 9, 2013
    Posts:
    108
    Hello,

    I have a serious problem with the asset since I linked my scenes together via
    SceneManager.LoadSceneAsync(levelToLoad, LoadSceneMode.Single)

    Both scenes contain many MeshAnimator characters. If I load the scenes directly everything works fine.
    If I load scene 1 and then load scene 2 via script, many of the MeshAnimator characters are invisible or flickering.
    I know that they are all there and that the animations are playing, since I can see the objects I assigned to their root bones. Any idea where this comes from? I experienced it with multiple different scene combinations but only if I load one scene from another.
     
  41. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    I have not encountered this issue yet, but I'll test out your scenario and get a fix for it
     
  42. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    I'm trying to replicate the issue but I can't get the bug to happen. Can you PM me some more details?
     
  43. noahx

    noahx

    Joined:
    Nov 22, 2010
    Posts:
    77
    Hi again,
    I've been using mesh animator for some months now and I've been happy with it, even though I don't have hundreds of models (just around 100 of the same model, just instances of the same one) but I feel like I'm not getting it's full potential in terms of performance even when the model I'm replicating is considered "low poly" (~600tris) with just a few short animations. I need to say that it is faster than using the animation component for sure.
    So, my question is, since I've been hearing a lot of buzz around "GPU instancing" and it is advertised as a feature "out of the box" in Mesh Animator, How do I get benefit from it? Does that require anything specific? How do I know if things are getting GPU instanced?

    I want to make sure I'm doing the things right to get the most out of this great tool.

    Thanks.
     
  44. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    You need to use shaders on your materials that support GPU instancing, Unity will handle the rest. You'll see that mesh's displaying the same frame of animation will be instanced in your stats viewer.

    https://docs.unity3d.com/Manual/GPUInstancing.html
     
  45. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    JBR-games likes this.
  46. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
  47. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Hello,

    I'm having trouble getting any animations to start playing on my character. I'm wanting to use the MecanimMeshAnimatorController.cs script (i.e. use Mecanim). I've read the documentation, but maybe I'm not understanding something. I have populated both the Animator and Mesh Animator inspector slots with the appropriate "Animator" I'm using on the character, and with the Mesh Animator script on the character as well. I also have the "Play Automatically" option checked. But I'm not seeing my character moving/animating at all during the game.

    I'm seeing the "Current Frame" in the inspector cycling through frames.....so the animations seem to be playing or running, but my character/mesh is not animating for some reason.

    I thought the MecanimMeshAnimatorController script would simply read the mecanim Animator component on my character and play whatever animations it's playing? I've checked the names of the states, and they're all the same. Do I need to manually code the MecanimMeshAnimatorController to start playing, or perhaps the Mesh Animator script, or both?

    Does the MecanimMeshAnimatorController auto transition to another animation when the Animator transitions? Or do I need to code all of the transitions manually as well?

    I'm just confused on how exactly to use the system. Thanks for any help or clarification.
     
    Last edited: May 6, 2018
  48. ashwinFEC

    ashwinFEC

    Joined:
    May 19, 2013
    Posts:
    49
    I've just bought your asset on sale. I'm very happy with the result. But I have a request. Do you think it's possible to let your system bake the vertex position data and normals into a texture so a shader can do the vertex displacement and modify normals? So animations can run entirely on the GPU. Jonas Norberg from Zynga managed to do that in Unity
    so it is possible.
     
    hopeful and JBR-games like this.
  49. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    S
    Sorry for the delayed response, was getting married over the weekend!

    It seems to me that it's possible the character was not baked properly, but it's hard to say without actually seeing it. MecanimMeshAnimatorController should handle the transitioning of states properly, and judging off of what you described, you seem to have it setup correctly. Would it be possible for you to PM me the character and I can debug it further?
     
  50. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    Yes this is totally possible and was on my roadmap for the future. However, it's a very specific solution for a very specific problem, and I'd probably make it a separate asset outside of Mesh Animator.

    Also, Unity just created something very similar and it's open source! Performance and ease of use doesn't seem quite as good as MA, but you can have a look at the blog post here: https://blogs.unity3d.com/2018/04/16/animation-instancing-instancing-for-skinnedmeshrenderer/