Search Unity

Number of bind poses doesn't match number of bones in...

Discussion in 'Editor & General Support' started by SpeedAdict, Sep 6, 2009.

  1. SpeedAdict

    SpeedAdict

    Joined:
    Aug 9, 2009
    Posts:
    8
    Hi,

    What is exactly the meaning of this error message:

    "Number of bind poses doesn't match number of bones in skinned mesh."

    This happens when I'm trying to replace one of the skinned meshes of my character mix and match system. The code I use to replace the meshes is here:

    Code (csharp):
    1.  
    2.     var MySkinRenderer : SkinnedMeshRenderer = obj.GetComponent(SkinnedMeshRenderer);
    3.                
    4.     DebugMeshName = MeshFileName();
    5.    
    6.     var instance : GameObject = Instantiate(Resources.Load(DebugMeshName));
    7.  
    8.     if (instance)
    9.     {
    10.         var OtherSkinRenderer : SkinnedMeshRenderer = instance.GetComponentInChildren(SkinnedMeshRenderer);
    11.  
    12.         if (!OtherSkinRenderer)
    13.         {
    14.             Debug.LogError("Unable to load other skin renderer.");
    15.         }
    16.        
    17.         MySkinRenderer.sharedMesh = OtherSkinRenderer.sharedMesh;   // <---- Error happens here.   
    18.         Destroy(instance);
    19.        
    20.         Debug.Log("Using " + DebugMeshName);
    21.     }
    22.  
    Also, if possible please let me know if this is the best way of exporting the files / partitioning the data. From the code it can be inferred how the files are exported.

    Thanks a lot
     
  2. SpeedAdict

    SpeedAdict

    Joined:
    Aug 9, 2009
    Posts:
    8
    Hi guys, we're really struggling with this error.

    Could somebody tell us what the message "Number of bind poses doesn't match number of bones in skinned mesh" means exactly? How do we get around it?

    It would be much appreciated.

    Thanks a lot
     
  3. SpeedAdict

    SpeedAdict

    Joined:
    Aug 9, 2009
    Posts:
    8
    Come on guys, please some help from those who have access to the source code of the engine.

    This is being a major problem to us as some meshes work and other meshes don't work for apparently no reason.

    Thanks
     
  4. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    I had that error once. For me it ment that I had a mismatch between the number of bones in the mesh and in the animation. But cant see what this has to do with the material? are you doing other stuff too???

    hope it helps.

    //perlohmann
     
  5. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    SpeedAdict,

    I don't think that there is any mystery to this error message. As perlohmann said, Unity is checking that everything looks correct, and has found that the number of matrices used to represent the bind pose differs from the number of bones in the model.

    Referring to:

    http://unity3d.com/support/documentation/ScriptReference/SkinnedMeshRenderer-bones.html

    just for simplicity, you would get this message if bindPoses has a different size to bones.

    You get this error in your code when you copy across the meshes, because it is at that time Unity knows there is a new mesh to consider. This has nothing to do with materials.

    Without access to your models it is hard to tell you *why* these objects differ in size, but it should be relatively quick for you to figure out the difference and go back to your modeller and fix.

    Hope that helps you. Out of curiosity, what did you think the error message meant? Is there anything you would recommend that we change the message to? The only confusing thing I can think of is that perhaps "bind poses" should be written as "bindPoses" to help indicate it is the bindPoses member of the SkinnedMeshFilter that is involved.

    Graham
     
  6. Lucas Meijer_old

    Lucas Meijer_old

    Joined:
    Apr 5, 2008
    Posts:
    436
    Hey, I haven't looked closely at what might be wrong with your code, but I figured that the code snippet below might help a bit. It's not really mixing meshes, but reassigning skinnedmeshrenderers from one skeleton to another.

    hope it helps,

    Lucas

    Code (csharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4.  
    5. static class SMRendererToGameObjectCopier
    6. {
    7.     /// <summary>
    8.     /// Takes a target GameObject and an array of GameObjects. All skinned mesh renderers attached to any GameObject in the array are copied to the target GameObject.
    9.     /// </summary>
    10.     public static void CopySMRenderersToGameObject(GameObject target, GameObject[] gameObjectsToCombine)
    11.     {
    12.         // Record start time for logging time spent
    13.         float startTime = Time.realtimeSinceStartup;
    14.  
    15.         // Step through all game objects in gameObjectsToCombine
    16.         foreach (GameObject go in gameObjectsToCombine)
    17.         {
    18.             // Retrieve all skinned mesh renderers from this game object and its children
    19.             Component[] comps = go.GetComponentsInChildren(typeof(SkinnedMeshRenderer), true);
    20.             foreach (Component comp in comps)
    21.             {
    22.                 // Copy this skinned mesh renderer to the target game object
    23.                 CopySMRenderer((SkinnedMeshRenderer)comp, target);
    24.             }
    25.         }
    26.  
    27.         // Log time spent
    28.         Debug.Log("Combining game objects took " + (Time.realtimeSinceStartup - startTime) * 1000 + " ms");
    29.     }
    30.  
    31.     static void CopySMRenderer(SkinnedMeshRenderer renderer, GameObject target)
    32.     {
    33.         // Create a new game object to avoid overwriting the skinned mesh renderer component as we will add them to the same game object
    34.         GameObject go = new GameObject("Merged Geometry: " + renderer.name);
    35.         // Create a new skinned mesh renderer
    36.         SkinnedMeshRenderer smr = (SkinnedMeshRenderer)go.AddComponent(typeof (SkinnedMeshRenderer));
    37.         // Copy the mesh to the new game object
    38.         smr.sharedMesh = renderer.sharedMesh;
    39.         // Copy the material to the new game object
    40.         smr.sharedMaterials = renderer.sharedMaterials;
    41.  
    42.  
    43.         // To remap the skinning to the target skelleton we need to create an array that holds references to the bones in the target skelleton
    44.         // that correspond to the bones the original renderer is using. We find the bones by name.
    45.  
    46.         // Create an array to store references to the bones in the target skelleton
    47.         Transform[] bones = new Transform[renderer.bones.Length];
    48.         // Step through all bones used by the original renderer
    49.         for (int bone = 0; bone < renderer.bones.Length; bone++)
    50.         {
    51.             Transform t = null;
    52.             // Step through all transforms in the target game object
    53.             foreach (Component c in target.GetComponentsInChildren(typeof(Transform)))
    54.             {
    55.                 // Check if we have found the corresponding bone
    56.                 if (c.name == renderer.bones[bone].name)
    57.                 {
    58.                     t = c.transform;
    59.                     break;
    60.                 }
    61.             }
    62.  
    63.             // Throw an exception when we dont find a bone with the same name
    64.             if (t == null) throw new Exception("Bone not found: " + renderer.bones[bone].name);
    65.             // Add the bone we found to the array
    66.             bones[bone] = t;
    67.         }
    68.  
    69.         // Set the bones array to make the new skinned mesh renderer use the target skelleton
    70.         smr.bones = bones;
    71.         // Attach the new game object holding the new skinned mesh renderer to the target game object
    72.         go.transform.parent = target.transform;
    73.     }
    74. }
    75.  
     
  7. polygrafix

    polygrafix

    Joined:
    Sep 4, 2009
    Posts:
    32
    Hey Guys,

    I am the modeler for the project. i consider myself pretty technical.
    I've been racking my brain with this, its been very hit or miss and unpredictable for me to get it to work.
    So here is whats happening:
    we have a placeholder mesh combined with the animation file. That placeholder mesh is for a specific section of body, IE: head, hair, Upperbody, Lowerbody,and shoes. Each mesh is a template because it stores the information in its skinned mesh which bones will be referenced when it used the real meshes for the same section of body.
    The real mesh's is located in a seperate file and exported out.
    The bone count is identical between the skinned mesh of the(placeholder) mesh and the actual mesh that swaps out.
    I've also made certain that all the verts in the mesh- refernce at least 1 bone that is being used by the placeholder mesh.
    The only differnce between a placeholder mesh and one of the real skinned meshs that replace it are:
    Vert count
    Vert position

    I've been able to make about 1/2 of all the meshs work correctly. and i cannot pinpoint (through much trial and error) what is causing the problem.

    Many of the mesh show up - but when they animate- they deform crazy and verts re-position themselves all over.

    I usually clean a mesh ( we use 3ds max 2009) by resetting the exform and collapsing it back to an editable poly before applying the skin- as to reset the transformation of the mesh.

    any ideas?
     
  8. RElam

    RElam

    Joined:
    Nov 16, 2009
    Posts:
    375
    I'm running into this problem with just decimating a mesh, and using it as a skinned LOD. Basically, my lowest level LOD model will fail, but all others work fine (only difference in lowest LOD is a higher setting when decimating with Multires in max). While I can see why this is happening, I'd think Unity could fix this, since it seems something is just removing unused bones and kicking in the exception.
     
  9. Noggy

    Noggy

    Joined:
    Feb 8, 2011
    Posts:
    2
    Today we were able to pinpoint exactly what was causing this issue for us. Our modeler is using 3dsmax and we were getting these issues intermittently on our character during skinned mesh swapping. It turns out that the FBX files that were failing were ones where the a single skinned mesh component had multiple materials. When imported into unity the separate materials were being changed into sub-meshes. After removing the separate materials we re-imported and everything started working.

    Please excuse me if my terminology is a little off, I'm a programmer not a modeler =o)

    I just hope this helps anyone from wasting the same amount of time we did trying to get this solution
     
  10. tmccullough

    tmccullough

    Joined:
    Mar 23, 2011
    Posts:
    2
    Hi guys,

    looks as though you need to replace the animated prefab in the scene.
    I've been beating my head against a brick wall for the past few days.
    Trying all kinds of crazy changes.

    replacing the character prefab in all the levels worked.

    In the future it looks like it would be best for us to load the prefab dynamically when the scene is loaded.
     
  11. psdev

    psdev

    Joined:
    Feb 11, 2011
    Posts:
    53
    I had a similar issue (i.e. receiving the same error message) when re-importing a package containing the prefab with the good fbx. I was reimporting in order to reset to defaults a modified version of the prefab. Turns out that deleting the prefab from the scene and re-adding it to the scene fixed this issue after the re-import.

    Also of note: if you have scripts attached to your prefab/fbx and you re-import the package - it will overwrite existing scripts in your project with the same name without telling you it is overwriting them!! yikes,
     
  12. Don Goddard

    Don Goddard

    Joined:
    Sep 25, 2010
    Posts:
    21
    It would help a huge amount if you could tell us the NUMBER of bones and/or the NUMBER of bind poses that have been found. Just telling us it's different is okay but telling us how MUCH it's different gives us clues as to what to look for. Plus, there is a lot of wasted time and guesswork having to write a bunch of test code to attempt to figure out what the internal engine is computing and failing on. Also, any indication of what file and line number it's failing at helps as well.

    I'm currently having this bones/bindposes problem myself so I'm having the artist export the model as FBX in ASCII text mode. THAT is a great help so far. Still, I'm having to write code, figure out how to use the debugger, scan through large exported FBX files and currently banging my head against the wall.
     
  13. Pheck

    Pheck

    Joined:
    Jul 9, 2009
    Posts:
    225
    I just ran into this issue at home in unity; at work we use ue3 and when this happens the engine fails gracefully. it would be nice if unity did that also.

    what I am getting at home right now is a error message and the unit doesnt update correctly. at work it would throw a error 1 time not forever and then allow the user to keep working as normal. the engine would do its best to apply the animation based on bone names/hierarchy. if the animation looked wrong it was contents job to find out why but it didnt completly block production because of a missmatch.

    I would recommend a similar approach for unity. if this is what unity is doing than more research is needed because my current situation is causing me to stop all production on the skel mesh i am building at home to figure out why its not integrated correctly.

    detailed error messages are great but sometimes production needs to move forward and allow the error to be fixed at a different time.
     
  14. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    I had this problem when I removed some bones from a legacy mesh. All of a sudden, the old animations (imported using Store In Root) no longer worked, and instantiating the Player prefab generated this error.

    Rebuilding the prefab from the newly-imported mesh got rid of the errors. (Unfortunately, animation now seems to fail silently. When I figure that out, I'll let you know.)

    Edit: Drag-and-dropping animations from an old (pre-bone-deletion) copy of my Player skinned mesh into the Prefab (with the new, post-bone-deletion mesh and armature) makes the old animations magically work as well as they ever did.

    Whaaaaaaaat? You're telling me that Unity is smart enough to map an animation with too many bones to an animated mesh lacking some of those bones? If that's the case, then why did deleting some bones cause my prefab to stop working? Why not just, instead of printing the error message, use the bones you can find? Unity has just demonstrated that it already has this functionality!

    The moral of my story is simple: Even Unity has a pipeline. Learn it. Obey it.
     
    Last edited: Jun 2, 2011
  15. tom.penney

    tom.penney

    Joined:
    Oct 28, 2011
    Posts:
    3
    I have a been baffled with a problem with the weapon system for hours.
    I can buy weapons in the shop system, and it recognises how many of them I own, but I cannot equip them - the equip menu doesn't recognise them and nor does the Event system (if I want an event to equip a weapon) in the weapon choice box it has nothing, I cant click to select any of the weapons I have outlined in the Project Editor. It was working with one of the default "Long Sword" items that came with the package, but not the "short sword". I don't know why. :( I've definitely defined where the items can be equipped, and I've added weapon viewers, and they have prefabs and everything).

    TP
     
  16. carllooper

    carllooper

    Joined:
    Aug 8, 2009
    Posts:
    64
    To work around limitations in the way Lightwave exports FBX, I'm parsing a Collada file and reassigning weights, bones, bindposes and a mesh like so (doing much the same thing as: http://unity3d.com/support/documentation/ScriptReference/Mesh-boneWeights.html )

    mesh.boneWeights = weights;
    renderer.bones = bones;
    mesh.bindposes = bindposes;
    renderer.sharedMesh = mesh;
    Debug.Log("renderer.sharedMesh.bindposes.Length = " + renderer.sharedMesh.bindposes.Length.ToString());
    Debug.Log("renderer.bones.Length = " + renderer.bones.Length.ToString());


    And this is the log:

    renderer.sharedMesh.bindposes.Length = 23
    renderer.bones.Length = 23


    So clearly, at this point, Unity is reporting they are the same length, but then Unity immediately throws the following error :

    Number of bind poses doesn't match number of bones in skinned mesh.

    Which the console reports as an error in Line 277 of one of Unity's files: UnityGUIUtility.cs

    The error message is simple enough to understand. That's not the problem. The problem (obviously) is that it's inconsistent with what Unity had moments earlier reported: that there were 23 of each.
     
    Last edited: Dec 5, 2011
  17. blueshadow1109

    blueshadow1109

    Joined:
    Jun 22, 2011
    Posts:
    11
    Yeah~! We just got the same error message and we found the reason is that: the programmer is creating an assetbundles to access a cloth changing system and this requires one mesh one material. And when the model have 2 materials , unity give an error message "Number of bind poses doesn't match number of bones in skinned mesh."
    After delete the other material, it goes OK.

    This our situation. Hope helps someone get the same error message...
     
  18. artician

    artician

    Joined:
    Nov 27, 2009
    Posts:
    345
    Really? I am using a system right now where I have multiple materials on a single mesh. Art Direction for my current project is based around flat color with spec, no diffuse maps. I have characters that have up to at least 3 separate materials on them, but they were not split into sub-meshes, and I did not receive the skeletal error.

    Why would that affect you and not me?
     
  19. boneyard24

    boneyard24

    Joined:
    May 5, 2011
    Posts:
    17

    I am doing the exact same thing/having the exact same problem.

    I have a series of assetbundles for skinned mesh renderer swapping for my custom clothing system and some of the models have a second material on them, which contains the alpha texture for the model. I need that second material but it seems that I can't do that so I'm unsure of what my options are other than remove the material.

    If Unity is creating a sub-mesh for the second material can I just create that into an additional assetbundle and load it that way? I'm just confused on how I solve this while retaining my alphas
     
  20. AnthonyPaulO

    AnthonyPaulO

    Joined:
    Nov 5, 2010
    Posts:
    110
    I dealt with this more almost 2 years ago in great detail when I created my Skinz framework, but things are a bit fuzzy now... off the top of my head, I'm somewhat confident that in the normal case a sub-mesh exists for each material present. You can have more materials than sub-meshes, but what happens is that the last sub-mesh will have multiple materials assigned to it, which essentially layers the textures on top of each other on to that sub-mesh according to each materials' shader. For example, if you have one mesh with only one sub-mesh and three materials, then those three materials are going to be layered on to the same mesh. If you have one mesh with 2 sub-meshes and three materials, then the first sub-mesh will get the first material, and the second sub-mesh will get the second and third material layered on to it. Please correct me if I'm wrong, but this is how I remember it.

    I too came across the same "Number of bind poses" error back then and it was a result of my mishandling the bones structure when combining meshes, so you have to do a lot of studying on exactly how everything works together to resolve it. I was well versed at one point, but I'm a bit rusty now since we don't usually deal at this level on a regular basis.

    .
     
  21. boneyard24

    boneyard24

    Joined:
    May 5, 2011
    Posts:
    17
    ok with that being said then I should be able to create assetbundles that contain my skinned mesh renderer with more than a single material?
     
  22. AnthonyPaulO

    AnthonyPaulO

    Joined:
    Nov 5, 2010
    Posts:
    110
    Sure, you can create it any which way you want, but knowing precisely how is the question. Study Unity's CharacterCustomization demo and see how they do the combine mesh portion.

    BTW, what *exactly* are you trying to do?
     
  23. boneyard24

    boneyard24

    Joined:
    May 5, 2011
    Posts:
    17
    Pretty much the exact same thing as the CharacterCustomization Dressing Room Demo. You have a character that is able to change their current outfit via asset bundles.

    Everything works fine except for the items that have 2 materials on them, those items contain an alpha texture which I need. All the single material/mesh items work fine and I can swap those without an issue but when I try to swap an item that has the additional material I get the error.

    Eg. I have my base object, contains all my bones etc, then I load in 6 meshes. The player model, the headpiece, the body, legs, hands, feet and combine.

    Code (csharp):
    1.  
    2.        AssetBundle coreBundle = bundleLoader.GetBundle("custommale_characterbase");
    3. coreModel = (GameObject)Instantiate(coreBundle.mainAsset);
    4.  
    5. List<Material> materials = new List<Material>();
    6. List<CombineInstance> combineInstance = new List<CombineInstance>();
    7. List<Transform> bones = new List<Transform>();
    8. Transform[] transforms = coreModel.GetComponentsInChildren<Transform>();
    9.  
    10.        
    11. foreach (KeyValuePair<string, AssetBundle> bundle in currentOutfit)
    12. {
    13.  
    14.     GameObject gSMR = (GameObject)bundle.Value.Load("rendererobject", typeof(GameObject));
    15.  
    16.     SkinnedMeshRenderer smr = gSMR.GetComponent<SkinnedMeshRenderer>();
    17.          
    18.     materials.AddRange(smr.materials);            
    19.  
    20.     for (int i = 0; i < smr.sharedMesh.subMeshCount; i++)
    21.     {
    22.         CombineInstance ci = new CombineInstance();
    23.         ci.mesh = smr.sharedMesh;
    24.         ci.subMeshIndex = i;
    25.         combineInstance.Add(ci);
    26.     }
    27.  
    28.     StringHolder bonenames = (StringHolder)bundle.Value.Load("bonenames", typeof(StringHolder));
    29.  
    30.     for (int i = 0; i < bonenames.content.Length; i++)
    31.     {
    32.                
    33.         foreach (Transform t in transforms)
    34.         {
    35.             if (t.name != bonenames.content[i]) continue;                  
    36.             bones.Add(t);
    37.             break;
    38.         }
    39.     }
    40.            
    41. }
    42.  
    43.        
    44. SkinnedMeshRenderer r = coreModel.GetComponent<SkinnedMeshRenderer>();
    45. r.sharedMesh = new Mesh();
    46. r.sharedMesh.CombineMeshes(combineInstance.ToArray(), false, false);
    47. r.bones = bones.ToArray();
    48. r.materials = materials.ToArray();
    49.  
     
    Last edited: Jul 18, 2012
  24. boneyard24

    boneyard24

    Joined:
    May 5, 2011
    Posts:
    17
    Ok I solved my problem here and would like to share, it's kind of ridiculous and I don't completely understand why.

    I had a feeling that my combining scripts was fine after a little digging around so I went back to where I create my assetbundles and bone association. I even noticed that when I attempted to build my model and when I would receive the error

    Debug.Log("Total Bones: " + r.bones.Length);
    Debug.Log("Total Bindposes: " + r.sharedMesh.bindposes.Length);

    that these two values were not matching, hence the error. However, the difference between these two values happened to be the exact bone length for the mesh that was causing the problem.

    AnthonyPaulO educated me briefly on how Unity works with materials and sub meshes so in my case if I have 2 sub meshes then I should probably double check to make sure I am performing two sets of bone listing. I figure if my bone count is wrong, and the difference between my bones and poses happened to be the same value as my mesh that I could just double the bone count for that model and be good!

    So I literally changed this:
    Code (csharp):
    1.  
    2. //MATERIALS
    3. foreach (Material mats in smr.sharedMaterials)
    4. {
    5.     //Debug.Log(mats.name);
    6.     foreach (Material m in materials)
    7.     {
    8.         if (mats.name.ToLower() == m.name.ToLower())
    9.         {
    10.             toInclude.Add(m);
    11.         }
    12.     }
    13. }
    14.  
    15.                    
    16. //BONES
    17. List<string> boneNames = new List<string>();
    18.  
    19. foreach (Transform t in smr.bones)
    20. {
    21.     boneNames.Add(t.name);
    22. }
    23.  
    To this:
    Code (csharp):
    1.  
    2. int number = 0;
    3. //MATERIALS
    4. foreach (Material mats in smr.sharedMaterials)
    5. {
    6.     //Debug.Log(mats.name);
    7.     foreach (Material m in materials)
    8.     {
    9.         if (mats.name.ToLower() == m.name.ToLower())
    10.         {
    11.             number++;
    12.             toInclude.Add(m);
    13.         }
    14.     }
    15. }
    16.  
    17.                    
    18. //BONES
    19. List<string> boneNames = new List<string>();
    20.  
    21. for (int i = 0; i < number; i++)
    22. {
    23.     foreach (Transform t in smr.bones)
    24.     {
    25.         boneNames.Add(t.name);
    26.     }
    27. }
    28.  
    and it works.

    I kind of understand why but it seems a little silly. Anyways I if you can make sense of my rambling I hope it helped.
     
  25. SpencerS

    SpencerS

    Joined:
    Jul 26, 2012
    Posts:
    3
    You rock my socks. Thanks.
     
  26. Rustam-Ganeyev

    Rustam-Ganeyev

    Joined:
    Jul 18, 2011
    Posts:
    29
    I have the same problem and have no idea how to deal with this.
    Could you explain what do u mean by removing and reimporting material? Just delete material file and import from fbx?
     
  27. Rustam-Ganeyev

    Rustam-Ganeyev

    Joined:
    Jul 18, 2011
    Posts:
    29
    I have problem related with multiple materials that cause creating multiple submeshes. Here's the code:
    Code (csharp):
    1.  
    2.    public void GenerateView() {
    3.        //bonedictionary - dictionary<string, Transform>, containing all bones in skeleton
    4.        //showedItems - 3d models to be shown, now it has only one model
    5.         var combineInstances = new List<CombineInstance>();
    6.         var bones = new List<Transform>();
    7.         var matSet = new HashSet<Material>();
    8.  
    9.         for (int i = 0; i < showedItems.Length; ++i) {
    10.             CustomizationItem item = showedItems[i];//CustomizationItem is wrapper class on gameobject, contains link to meshrenderer, some additional info
    11.             SkinnedMeshRenderer smr = item.GetSkinnedMeshRenderer();
    12.  
    13.             foreach (Material material in smr.materials) {
    14.                 matSet.Add(material);
    15.             }
    16.  
    17.             Debug.Log(smr.bones.Length);
    18.             Debug.Log(smr.sharedMesh.bindposes.Length);
    19.             //They are equal
    20.             for (int sub = 0; sub < smr.sharedMesh.subMeshCount; sub++) {
    21.                 var ci = new CombineInstance();
    22.                 ci.mesh = smr.sharedMesh;
    23.                 ci.subMeshIndex = sub;
    24.                 combineInstances.Add(ci);
    25.             }
    26.             bones.AddRange(smr.bones.Select(bone => boneDictionary[bone.name]));
    27.             item.DestroyGameObject();
    28.         }
    29.  
    30.         agentSkinRenderer.sharedMesh = new Mesh();
    31.         agentSkinRenderer.sharedMesh.CombineMeshes(combineInstances.ToArray(), false, false);
    32.         agentSkinRenderer.bones = bones.ToArray();
    33.         Debug.Log(bones.Count + "\n" + agentSkinRenderer.sharedMesh.bindposes.Length); //different
    34.         agentSkinRenderer.materials = matSet.ToArray();
    35.     }
    36.  
    I tried to delete model's material and reimport, but it didn't work. What I'm doing wrong? How to handle this?
     
  28. Ryuzul

    Ryuzul

    Joined:
    Feb 1, 2013
    Posts:
    2
    I had a problem relating to this error and solved it. Apparently what our problem was that the base model we were using had a mesh skinned to bone A while the other mesh I was swapping it with didn't have a mesh skinned to bone A. So the root bone that were assign by Unity for these two meshes were different. Solution we're going to try tomorrow is to skin something to said bone A. So if you have this problem, check your root bones for your skined mesh renderers. Hope this helps!
     
  29. holwerdacompany

    holwerdacompany

    Joined:
    May 8, 2013
    Posts:
    1
    Definitely. Unity enables errors that are needles in a haystack to cripple the entire engine. Petty errors preventing the entire game from compiling is bad for productivity. Any experienced programmer should realize however, that this phenomenon of the smallest error preventing the entire software from running is common in any language in any program.
     
  30. tmcsweeney

    tmcsweeney

    Joined:
    May 24, 2011
    Posts:
    20
    Just want to add my 2c to this thread. I had the same error crop up after an artist changed the skinning on a submesh to include a bone that it previously didn't reference. Reimporting the fbx created a new set of skinned mesh prefabs with the correct binding, but because we'd taken the original generated prefab, modified it by adding components and so forth, and then dragged it back into the project window to define a second prefab it broke when the meshes (and the automatically generated prefab) were updated.

    As far as I can tell the generated SkinnedMeshRenderer prefabs have a hidden bones[] array property that is populated with references to the bone transforms. The size of this array has to match the number of bones that the mesh is expecting. When the mesh was updated to include more bones, our SkinnedMeshRenderer prefabs weren't updated and everything broke.

    I didn't want to start from scratch with the clean auto-generated prefab and repeat all our changes to it, so I came up with an editor script that looks uses a working prefab as a template and corrects the bones array on the broken one.

    To use it, drag an instance of your broken prefab into the scene. Then drag an instance of the working, automatically generated prefab into the scene, select the pair of matching SkinnedMeshRenderers in both the broken and the good hierarchies, and select the "Tools/SkinnedMeshRenderer/Fix Rig" menu option. If you've got multiple broken sub-meshes in the prefab hierarchy you'll need to fix each one up separately.

    No Warranty, Liability, YMMV, ETC:

    Code (csharp):
    1.  
    2.  
    3. using System;
    4. using System.Collections.Generic;
    5.  
    6.  
    7. using UnityEngine;
    8. using UnityEditor;
    9.  
    10. public static class SkinnedMeshRendererRigFix
    11. {
    12.   [MenuItem("Tools/SkinnedMeshRenderer/Fix Rig", true)]
    13.     public static bool ValidateFixRig(MenuCommand command)
    14.     {
    15.         bool bCanFix = false;
    16.         if (Selection.gameObjects.Length == 2)
    17.         {
    18.             GameObject a = Selection.gameObjects[0];
    19.             GameObject b = Selection.gameObjects[1];
    20.  
    21.             if (a.name == b.name)
    22.             {
    23.                 SkinnedMeshRenderer aRenderer = a.GetComponent<SkinnedMeshRenderer>();
    24.                 SkinnedMeshRenderer bRenderer = b.GetComponent<SkinnedMeshRenderer>();
    25.                 if (aRenderer != null  bRenderer != null)
    26.                 {
    27.                     if (aRenderer.sharedMesh != null  bRenderer.sharedMesh != null)
    28.                     {
    29.                         bool aBroken = false;
    30.                         bool bBroken = false;
    31.                         if (aRenderer.sharedMesh.bindposes.Length != aRenderer.bones.Length)
    32.                         {
    33.                             aBroken = true;
    34.                         }
    35.                         if (bRenderer.sharedMesh.bindposes.Length != bRenderer.bones.Length)
    36.                         {
    37.                             bBroken = true;
    38.                         }
    39.                         if ((aBroken || bBroken)  (aBroken != bBroken))
    40.                         {
    41.                             bCanFix = true;
    42.                         }
    43.  
    44.                     }
    45.                 }
    46.             }
    47.         }
    48.         return bCanFix;
    49.     }
    50.  
    51.     [MenuItem("Tools/SkinnedMeshRenderer/Fix Rig")]
    52.     public static void FixRig(MenuCommand command)
    53.     {
    54.         if (Selection.gameObjects.Length == 2)
    55.         {
    56.             GameObject a = Selection.gameObjects[0];
    57.             GameObject b = Selection.gameObjects[1];
    58.  
    59.             if (a.name == b.name)
    60.             {
    61.                 SkinnedMeshRenderer aRenderer = a.GetComponent<SkinnedMeshRenderer>();
    62.                 SkinnedMeshRenderer bRenderer = b.GetComponent<SkinnedMeshRenderer>();
    63.                 if (aRenderer != null  bRenderer != null)
    64.                 {
    65.                     if (aRenderer.sharedMesh != null  bRenderer.sharedMesh != null)
    66.                     {
    67.                         bool aBroken = false;
    68.                         bool bBroken = false;
    69.                         if (aRenderer.sharedMesh.bindposes.Length != aRenderer.bones.Length)
    70.                         {
    71.                             aBroken = true;
    72.                         }
    73.                         if (bRenderer.sharedMesh.bindposes.Length != bRenderer.bones.Length)
    74.                         {
    75.                             bBroken = true;
    76.                         }
    77.                         SkinnedMeshRenderer good = null;
    78.                         SkinnedMeshRenderer broken = null;
    79.                         if (aBroken  !bBroken)
    80.                         {
    81.                             broken = aRenderer;
    82.                             good = bRenderer;
    83.                         }
    84.                         else if (bBroken  !aBroken)
    85.                         {
    86.                             broken = bRenderer;
    87.                             good = aRenderer;
    88.                         }
    89.                         if (good != null  broken != null)
    90.                         {
    91.                             Debug.Log(string.Format("Fixing {0} from {1} ({2} bones)", broken, good, good.bones.Length), broken);
    92.                             Transform[] newBones = new Transform[good.bones.Length];
    93.                             bool foundAll = true;
    94.                             for (int i = 0; i < newBones.Length; i++)
    95.                             {
    96.                                 string goodBoneName = good.bones[i].name;
    97.                                 GameObject newBone = FindNodeWithName(broken.rootBone.gameObject, goodBoneName);
    98.                                 if (newBone != null)
    99.                                 {
    100.                                     Debug.Log(string.Format("Found Bone {0}", newBone.name), newBone);
    101.                                     newBones[i] = newBone.transform;
    102.                                 }
    103.                                 else
    104.                                 {
    105.                                     Debug.LogError(string.Format("Failed to find bone named {0} in Rig {1}", goodBoneName, broken.rootBone.name), broken.rootBone);
    106.                                     foundAll = false;
    107.                                 }
    108.                             }
    109.                             if (foundAll)
    110.                             {
    111.                                 Debug.Log("Setting Bones...");
    112.                                 broken.bones = newBones;
    113.                                 EditorUtility.SetDirty(broken);
    114.                             }
    115.                         }
    116.  
    117.                     }
    118.                 }
    119.             }
    120.  
    121.         }
    122.     }
    123.  
    124.     public static GameObject FindNodeWithName(GameObject go, string name)
    125.     {
    126.         if (go == null)
    127.         {
    128.             return null;
    129.         }
    130.  
    131.         if (go.name == name)
    132.         {
    133.             return go;
    134.         }
    135.  
    136.         foreach (Transform t in go.transform)
    137.         {
    138.             GameObject res = FindNodeWithName (t.gameObject, name);
    139.             if (res != null)
    140.             {
    141.                 return res;
    142.             }
    143.         }
    144.         return null;
    145.     }
    146. }
    147.  
    148.  
     
    Last edited: Oct 8, 2013
  31. Emihaa

    Emihaa

    Joined:
    Oct 17, 2012
    Posts:
    5
    I also want to apply this to the thread since I found the solution to mine:" Number of bind poses doesn't match number of bones in skinned mesh." error.
    I had character with armature/bones made for Unity which was already working on the scene. I went then back to the modeler program and added some new bones as that was what I needed for my stuff. As I imported my new character with his extra bones over the earlier one i got the error.
    As I opened the last character armature hierarchy (which game me the error now) I noticed it didn't have the new bones and that was because I had broken the prefab link between my character prefab on the scene. This is what gave me the error and just replacing the character with the new one will fix it.
     
    andreiagmu likes this.
  32. Tabrisx

    Tabrisx

    Joined:
    Jul 17, 2018
    Posts:
    1
    When I use Anima2D,import a .png with simple shape to sprite,create SpriteMesh,drag it into scene,create a bone as its child,drag the bone to Inspector/Set bones,then the error message comes.
    I also tried to Unbind SpriteMesh in office's example,then when I add bone to the SpriteMesh,the error messsage came out again.
    I didn't do anything special.How to fix it?
     

    Attached Files:

  33. amoraleite

    amoraleite

    Joined:
    Oct 16, 2014
    Posts:
    41

    2 years old... But I stated with anima2d right now :)
    For me I get same message. But I just ignore it and bind again, everything return to normal and I get rid of this message.
     
  34. AxonGenesis

    AxonGenesis

    Joined:
    Jun 24, 2016
    Posts:
    90
    I also ran into this issue but in my case the bindposes and bones had the same count with no submeshes and only 1 material each. The fix was to be sure to make a copy of the sharedMesh, rather than modify the original mesh directly.

    Code (CSharp):
    1. head_mesh.sharedMesh = (Mesh)UnityEngine.Object.Instantiate(head_mesh.sharedMesh);