Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Mesh Animator - Highly efficient animated crowds, fully animated GPU instancing, and more!

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

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    have you run into this... and fixed it?
    Seems to happen when switching to another scene
    Code (CSharp):
    1. ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    2. Parameter name: index
    3. System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <9577ac7a62ef43179789031239ba8798>:0)
    4. System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <9577ac7a62ef43179789031239ba8798>:0)
    5. System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <9577ac7a62ef43179789031239ba8798>:0)
    6. FSG.MeshAnimator.Snapshot.SnapshotMeshAnimator.ReturnCrossfadeToPool (System.Boolean destroying) (at Assets/Scripts/MeshAnimator/Scripts/Snapshot/SnapshotMeshAnimator.cs:348)
    7. FSG.MeshAnimator.MeshAnimatorBase.OnDestroy () (at Assets/Scripts/MeshAnimator/Scripts/Common/Core/MeshAnimatorBase.cs:183)
    8. FSG.MeshAnimator.Snapshot.SnapshotMeshAnimator.OnDestroy () (at Assets/Scripts/MeshAnimator/Scripts/Snapshot/SnapshotMeshAnimator.cs:269)
    9.  
     
    chadfranklin47 likes this.
  2. Jmonroe

    Jmonroe

    Joined:
    Jul 7, 2012
    Posts:
    111
    Just thought I'd reply as we're on our own for now. I'm using 2020.2.2 [need to update to LTS] and I've check for this changing scene error and I am not able to duplicate when switching back and forth between my Title scene and Game scene.
    In my game scene I spawn around 1200 mesh animator characters which were baked from snapshot mode, but I do not use Crossfade. I just couldn't get it to work so I baked some transition animation clips instead. I see you're error log mentions ReturnCrossFadeToPool. Would it be possible to disable crossFade in your code and see if the error still persists?
     
  3. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    136
    I haven't run into it yet as I am not doing any scene switching at the moment. I will be soon, so I'll be on the lookout for it and let you know if I manage to fix anything though.
     
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    Thanks for the hint. I looked at crossfade code: it uses a job to generate intermediate mesh, which then gets cached to avoid hitting the cpu a second time. It's rather clever but clearly broken and since I couldn't trace why that exception happened I commented out the crossfade. Now it runs without exceptions and I cannot tell the difference as it fits the cartoony style of animation.

    I don't know so I use caution out of experience: when my own pooling misbehaved in a similar way it was due to a flaw in logic and that caused all sorts of weird bugs, plus memory usage kept expanding.
     
  5. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    136
    Yeah, I wouldn't look past it. When you say you commented out the crossfade, you mean you're just not using crossfading at all anymore?
     
  6. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    Correct, Play() all the way.
     
    Klausology and chadfranklin47 like this.
  7. Jmonroe

    Jmonroe

    Joined:
    Jul 7, 2012
    Posts:
    111
    For clarification we are having issues with crossfade of snapshot mode. If I had to guess crossfade of shader mode is less troublesome... which should be based on creation of an image versus creation of meshes.

    Also it is important to note that in snapshot mode I'm getting very consistent callbacks of OnAnimationFinished(). So I was able to create my own 'crossfade' animations and use this method to play the next animation. However, creating the transition animations can be very tedious.

    Someday I plan to switch to shader mode, maybe next project, but only with a supported code base. This is an interesting asset where the plugin is much needed but the developer has gone AWOL. If he doesn't show up any time soon I would gladly pay someone to maintain the code. Just saying.
     
  8. avebury10

    avebury10

    Joined:
    Apr 16, 2020
    Posts:
    3
    I'm running into some basic issues so went back to the provided assets to see if I could even get the process working with them. Going through the SnapShot process with the provided HumanCrowd prefab and CrowdCrontroller the AnimatedMesh is created and the crowd snapshot anims but when running the scene the character is stuck in default pose with no animation running. The following error is kicked up over and over during the process:

    DivideByZeroException: Attempted to divide by zero.
    FSG.MeshAnimator.Snapshot.DeltaCompressedFrameData.op_Implicit (FSG.MeshAnimator.Snapshot.DeltaCompressedFrameData s) (at Assets/MeshAnimator/Scripts/Snapshot/SnapshotMeshFrameData.cs:82)
    FSG.MeshAnimator.Snapshot.SnapshotMeshAnimation.get_frameData () (at Assets/MeshAnimator/Scripts/Snapshot/SnapshotMeshAnimation.cs:35)
    FSG.MeshAnimator.Snapshot.SnapshotMeshAnimation.OnEnable () (at Assets/MeshAnimator/Scripts/Snapshot/SnapshotMeshAnimation.cs:55)
    UnityEditor.AssetDatabase:CreateAsset(Object, String)
    FSG.MeshAnimator.MeshAnimationCreator:CreateSnapshots() (at Assets/MeshAnimator/Editor/MeshAnimationCreator.cs:1798)
    FSG.MeshAnimator.MeshAnimationCreator:CreateSnapshots() (at Assets/MeshAnimator/Editor/MeshAnimationCreator.cs:1478)
    FSG.MeshAnimator.MeshAnimationCreator:OnGUI() (at Assets/MeshAnimator/Editor/MeshAnimationCreator.cs:912)

    And also the following once:
    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    FSG.MeshAnimator.Snapshot.SnapshotMeshAnimator.OnDestroy () (at Assets/MeshAnimator/Scripts/Snapshot/SnapshotMeshAnimator.cs:280)

    Unity version is 2020.2.7f1
     
  9. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    136
    With the shader mode, there seems to be some problem with shadows I can't put my finger on. It's weird because it doesn't happen all the time. Maybe just an issue with the outdated shaders:



    Edit: Tried updating the shaders myself and the shadow problem persists.
     
    Last edited: Apr 10, 2021
  10. Jmonroe

    Jmonroe

    Joined:
    Jul 7, 2012
    Posts:
    111
    Since I'm paranoid about the asset breaking I downloaded Unity2020LTS today [2020.3.3f1], created a blank project using 'Built In', switched to Android, and imported Mesh Animator and tested the MAExample_Crowd scene. Although there are script warnings and a camera GUI layer error that resolved itself I had no problem playing the scene as is. Then I proceeded to bake the HumanCrowd animations using snapshot mode to a different folder... again no issue. Then I had the spawner script spawn this new prefab in the demo and it worked as expected. I am pleased with these results.

    The details above are my settings for using MeshAnimator and they seem to work fine [for now]. Any other settings / platforms / rendering methods may have different results. Good luck!

    crowdExample.PNG bakedSuccess.PNG gui layer.PNG
     
    HenryChinaski and hopeful like this.
  11. avebury10

    avebury10

    Joined:
    Apr 16, 2020
    Posts:
    3
    Thanks. I tried it in a brand new project with the MeshAnimator assets and it worked fine with your settings which is reassuring. I'll go back and try and track down why it isn't working in the main project.
     
    Jmonroe likes this.
  12. Coco07

    Coco07

    Joined:
    Mar 7, 2017
    Posts:
    31
    Hi jschieck,

    I have 2 questions about the MeshAnimator: 1. Is there a way to lower the texture resolution in the Quality Settings without newly spawned MeshAnimator objects becoming invisible?

    2. As soon as I create a MeshAnimator, a unit appears in the overdraw scene which is at least 30 times as large as the original MeshAnimator object. This large object is only visible in this overdraw view and I was wondering if they are affecting performance in any way?
    Bildschirmfoto 2021-04-13 um 02.27.29.png

    Thank you in advice! :)

    Best,
    Coco 07
     
    ifisch likes this.
  13. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    a word of caution: if you load a scene and activate it, snapshot incurs a massive penalty
    upload_2021-4-18_19-54-45.png
    140 ms for 1 creature, again, that's not on instantiation of creature, that's on scene load.
     
    chadfranklin47 likes this.
  14. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    115
    Any idea what causes such a huge spike for OnEnable? I have not used snapshot mode but was intending on trying it out.
     
    chadfranklin47 likes this.
  15. parsec72

    parsec72

    Joined:
    Feb 27, 2020
    Posts:
    1

    @jschieck



    Hi , any chance you can provide an stadium spawner with a configurable de curvature and gaps?
    also any video tutorials besides the overview ones? an steep by steep to replicate the stadium scene would be great...
     
    Last edited: Apr 19, 2021
  16. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    It shouldn't happen until the object is instantiated and the scene is active so I chalk it to bug bug bug. Time to feed the player with fade to black.
     
    Klausology likes this.
  17. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    upload_2021-4-20_23-50-15.png
    even snapshot disappear so all the problems we're having are likely due to shoddy MeshAnimatorManager losing track of which clip to play.

    if you guys have spent a lot of time on this and it's still not working well and you can program decently, there is this really cool ECS shader animator that could use skilled programmer to convert to monobehavior, the base project works solidly, it's very simple and does crossfade well.

    https://github.com/maxartz15/VertexAnimation
     
    Last edited: Apr 21, 2021
  18. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    115
    Ouh no! Looks like there'll need to be quite a bit of fixes for mesh animator to work smoothly.
    Thanks for sharing the github link! That looks really cool, definitely will be trying it out!
     
  19. avebury10

    avebury10

    Joined:
    Apr 16, 2020
    Posts:
    3
    I'm looking for a little clarification on how exactly to set up the Mecanim Mesh Animator Controller. I have it added to the AnimatedMesh as well as the Animator with the correct controller. On the Mecanim Mesh Animator Controller, I assumed that I add the AnimatedMesh asset to the Mesh Animator field but is that correct? And what do I complete the Animator field with on the Mecanim Mesh Animator Controller? Dragging the original controller there does not work. Do I drag the same AnimatedMesh which has the animator with controller attached there?

    Thanks.
     
  20. HenryChinaski

    HenryChinaski

    Joined:
    Jul 9, 2013
    Posts:
    108
    Just put the MecanimMeshAnimatorController script on to the object with the MeshAnimator component and assign the very same object to the field "MeshAnimator". Assign the object that holds your Animator component to the field that says "Animator". Make sure that for each AnimationState in your controller, there is one MeshAnimator animation with the same name assigned to your MeshAnimator component.
     
  21. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    532
    Could anyone make a new tutorial for this asset? The owner maybe forget it.
     
  22. ifisch

    ifisch

    Joined:
    Jul 15, 2012
    Posts:
    33
    FYI: The documentation states that Unity 2018.3+ supports the new "version 2" of this plugin. However, The Unity Asset Store forced us to download the old version of the plugin until we switched over to Unity 2019.

    Perhaps the documentation needs to be updated or a setting needs to be changed on the asset store page.
     
  23. ifisch

    ifisch

    Joined:
    Jul 15, 2012
    Posts:
    33
    @Klausology and @jschieck

    Ever since upgrading to Unity 2020, my shader-animated meshes no longer appear, at all, if the game's "Texture Quality" is set to half-res or quarter-res.

    The shader mode prefabs only seems to appear, at all, if the project's "Texture Quality" is set to full-res.

    I've tested this in a completely empty project with nothing but this plugin, to verify that this isn't an issue with my project in particular. If the "Texture Quality" is set to anything but "Full-Res", the stadium full of people is empty, when set to shader-animated mode.

    I'm using the built-in standard render pipeline.

    This problem did not exist in Unity 2019.

    Please help!
     
    Last edited: May 12, 2021
  24. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    115
    Ouh that is interesting. I was never able to get mesh animator to show if the game's texture quality is set to anything but full res in Unity 2020. I have also never used this asset in Unity 2019.

    I did ask the developer back this back then but did not get a response, so I've just assumed that this asset does not work without full res.
     
    ifisch likes this.
  25. ifisch

    ifisch

    Joined:
    Jul 15, 2012
    Posts:
    33
    What I find very strange is that if the project is set to FULL RES and I drag and drop a shader-animated prefab into the scene, it appears just fine. But then if I change the settings to HALF RES, the prefab continues to be visible in the scene.

    However if I then drag and drop a different shader-animated prefab into the same scene, this second prefab is not visible. But if I drag and drop another instance of that first prefab into the scene, it is visible.

    Furthermore, if I bump texture quality back up to FULL RES, and drag and drop another instance of that second prefab into the scene it's still not visible.

    It's like whatever the Texture Quality setting happened to be, the first time an instance of the prefab is dragged into the current scene, is what seems to be controlling. It's very strange.
     
  26. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    115

    Ouh my. This issue appears to be more convoluted than I thought. I believe it is best we always set the texture quality at full res and never switch it to any other quality level (throughout the project's lifetime) when we are using this asset.
     
  27. ifisch

    ifisch

    Joined:
    Jul 15, 2012
    Posts:
    33
    Nah, here's the fix (in ShaderMeshAnimator.cs):
     
    Last edited: May 12, 2021
  28. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    115
    Ouh! You've figured it out! This is very useful! Thank you!
     
    ifisch likes this.
  29. Coco07

    Coco07

    Joined:
    Mar 7, 2017
    Posts:
    31
    @ifisch Thank you very much for sharing :)
     
  30. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    ouch the double negative
    why is copytexturesupport == none in 2020+?
     
    Klausology likes this.
  31. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    246
    @jschieck
    I bought your Mesh animator yesterday. I will use it for my mobile game. I am currently testing your sample scenes with 3 different phones and what I found is: enabling GPU instancing on material decreases performance on 2 of my testing devices. On other mobile device(galaxy s7) it increase performance...
    So what is the problem here? What should I do? Is it about gpu ?
    Samsung galaxy s7 has Mali-T880 gpu
    Other devices: General mobile g20 and samsung galaxy A10s which both have PowerVR Rogue GE8320 gpu
     
  32. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    246
    @jschieck
    Why developer is not active in this thread? This is a huge problem for us.
     
  33. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    It's abandonware.
    If you need to use it, read this thread, you'll see that this asset works well only in some very narrow conditions that emulate the samples.
     
    Quast and Klausology like this.
  34. windsmane

    windsmane

    Joined:
    Apr 25, 2020
    Posts:
    1
    Hi, We were trying to use Mesh animator for a crowd based game, to get the FPS to around 30+ (Using normal animators and skinned mesh renderers were killing fps when there are around 60+ characters in game).
    But, using the snapshot mode keeps on having a divide by zero error, and the URP shader in mesh animator keeps on throwing shader compiler errors.
    Any one knows how to fix any of these?
     
  35. Patrick-Goettert

    Patrick-Goettert

    Joined:
    Jun 25, 2014
    Posts:
    2
    Can you control individual instances with this asset?
    For instance, if I have hundreds of AI controlled humanoid gameobjects, can I use this just for rendering and decide on what needs to be rendered using my own AI scripts?
     
  36. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    You probably have a new version of URP which, as usual with the new stuff breaks backward compatibility.
    8.31 works

    It's a (very broken) replacement to the animation component
     
    Klausology likes this.
  37. MansoorAhmadKhan

    MansoorAhmadKhan

    Joined:
    Dec 30, 2018
    Posts:
    6
    For those who are having error in URP Lit Shaders

    Double click on the red error. It will open (dot)HLSL file.

    Replace this:
    inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
    {
    outSurfaceData = (SurfaceData)0;

    And

    void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData)
    {
    inputData = (InputData)0;

    upload_2021-7-2_20-6-9.png


    upload_2021-7-2_20-5-55.png
     
    Jmonroe and laurentlavigne like this.
  38. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    Testing the June update of Mesh Animator ... same nightmare:
    Shader @ runtime doesn't work at all on some objects, works on others.
    Editor time doesn't show up anything which makes scene building difficult.

    If the GPUShaderAnimator component is at the root of a prefab at least it shows up at runtime.
    If I expose the MA parameters to the inspector in the shader graph it shows up but doesn't animate.
    Init and serialization bugs is my guess. No time to fix this asset, maybe one of you knows about serialization enough to fix this.

    Overall buginess of this thing is too much for production. I'm reverting back to snapshot and skinmesh.
     

    Attached Files:

    Last edited: Jul 12, 2021
    Klausology likes this.
  39. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    58

    I've only spent a day on this but I've managed to get 10k animated meshes waving with different color palettes using some custom color palette swap shader code with an instanced uint for my palette index.
    There are only 4 palettes right now, but its just a proof of concept.
     
    Hobodi and Jmonroe like this.
  40. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    58
    My mesh isn't baked in Shader Animated mode unless I tick the box "Shader Graph Support". I also can't get the LOD to work. I move the camera but the animation framerate remains constant in game. I can see that the current frame doesn't change when I add an LOD with 0 FPS but the model continues to move.
     
    Last edited: Jul 22, 2021
  41. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    58
    The "GPU Shader Animated" script actually does nothing in Shader mode.
    I really just need to know if there is any way to control the animation when using Shader Animated mode.
     
    Last edited: Jul 22, 2021
  42. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,263
    yeah: something like GetComponent<ShaderAnimator>().Play ("clipname"); all by hand unless it's been converted from an animator FSM in which case... good luck with other problems ;)
     
  43. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    58
    I contacted the writer and he ironed out things with me over email. There's a little polish that needs to be done but I have all the functionality I need now I think. I'm going to try out crossfading animations and if that works I'll be super happy with the purchase overall.
     
  44. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    58
    Is there some sort of trick to make crossfade more reliable? Sometimes it just jerks into the new animation without blending.

    Video below.
     
    Last edited: Jul 29, 2021
  45. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    58
    Baked animations are horribly warped. Here is the ending frame before and after baking.
    upload_2021-8-1_13-13-37.png
     
  46. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    58
    This seems to be related to the "Foot IK" checkbox.
    upload_2021-8-1_15-40-36.png
     
    Jmonroe likes this.
  47. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    58
    I've gotten the animation to work without IK, but the rotation is wacky. If I bake the rotation into the animation it will always play in the same direction (he gets out of the car facing the same direction). If I don't bake the rotation it spins around like in the video.
    upload_2021-8-2_1-43-27.png
    The behavior is different in Shader Animated Mode in that "Root Motion Mode - Applied to Transform" does nothing.

    As you can see the animation plays perfectly through Mecanim, but the Snapshot Mesh Animation rotates uncontrollably.

    Snapshot.


    Shader Animated
     
  48. xtudioero

    xtudioero

    Joined:
    Jul 29, 2021
    Posts:
    1
    i used Mesh Animatore in my project using Shader Mode and also add Mesh Animater shader in the prefab. the problem is that it works nice in Unity Editor but when i make build for android and run the game in my android device the character is not showing in the game , please anyone can guide me . thanks

    upload_2021-8-2_14-38-56.png
     

    Attached Files:

  49. Jmonroe

    Jmonroe

    Joined:
    Jul 7, 2012
    Posts:
    111
    Did you try baking the animation clips rotation on import? I see in your video it is not baked.
    bakeRotation.PNG
     
  50. Jmonroe

    Jmonroe

    Joined:
    Jul 7, 2012
    Posts:
    111
    I only use Snapshot mode because some older GPUs will not support the Shader mode approach. But in Snapshot mode you'll need to play with resolution and animation clip length to keep RAM down on the device... check by profiling. I target <500MB total RAM (all assets / scripts / etc) for mobile.
    shaderMode.PNG
     
unityunity