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

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:

	var MySkinRenderer : SkinnedMeshRenderer = obj.GetComponent(SkinnedMeshRenderer); 
				
	DebugMeshName = MeshFileName();
	
	var instance : GameObject = Instantiate(Resources.Load(DebugMeshName));

	if (instance)
	{
		var OtherSkinRenderer : SkinnedMeshRenderer = instance.GetComponentInChildren(SkinnedMeshRenderer);

		if (!OtherSkinRenderer)
		{
			Debug.LogError("Unable to load other skin renderer.");
		}
		
		MySkinRenderer.sharedMesh = OtherSkinRenderer.sharedMesh;	// <---- Error happens here.	
		Destroy(instance);
		
		Debug.Log("Using " + DebugMeshName);
	}

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

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

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

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

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:

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

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

using System;
using UnityEngine;

static class SMRendererToGameObjectCopier
{
    /// <summary>
    /// 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.
    /// </summary>
    public static void CopySMRenderersToGameObject(GameObject target, GameObject[] gameObjectsToCombine)
    {
        // Record start time for logging time spent
        float startTime = Time.realtimeSinceStartup;

        // Step through all game objects in gameObjectsToCombine
        foreach (GameObject go in gameObjectsToCombine)
        {
            // Retrieve all skinned mesh renderers from this game object and its children
            Component[] comps = go.GetComponentsInChildren(typeof(SkinnedMeshRenderer), true);
            foreach (Component comp in comps)
            {
                // Copy this skinned mesh renderer to the target game object
                CopySMRenderer((SkinnedMeshRenderer)comp, target);
            }
        }

        // Log time spent
        Debug.Log("Combining game objects took " + (Time.realtimeSinceStartup - startTime) * 1000 + " ms");
    }

    static void CopySMRenderer(SkinnedMeshRenderer renderer, GameObject target)
    {
        // Create a new game object to avoid overwriting the skinned mesh renderer component as we will add them to the same game object
        GameObject go = new GameObject("Merged Geometry: " + renderer.name);
        // Create a new skinned mesh renderer
        SkinnedMeshRenderer smr = (SkinnedMeshRenderer)go.AddComponent(typeof (SkinnedMeshRenderer));
        // Copy the mesh to the new game object
        smr.sharedMesh = renderer.sharedMesh;
        // Copy the material to the new game object
        smr.sharedMaterials = renderer.sharedMaterials;


        // To remap the skinning to the target skelleton we need to create an array that holds references to the bones in the target skelleton
        // that correspond to the bones the original renderer is using. We find the bones by name.

        // Create an array to store references to the bones in the target skelleton
        Transform[] bones = new Transform[renderer.bones.Length];
        // Step through all bones used by the original renderer
        for (int bone = 0; bone < renderer.bones.Length; bone++)
        {
            Transform t = null;
            // Step through all transforms in the target game object
            foreach (Component c in target.GetComponentsInChildren(typeof(Transform)))
            {
                // Check if we have found the corresponding bone
                if (c.name == renderer.bones[bone].name)
                {
                    t = c.transform;
                    break;
                }
            }

            // Throw an exception when we dont find a bone with the same name
            if (t == null) throw new Exception("Bone not found: " + renderer.bones[bone].name);
            // Add the bone we found to the array
            bones[bone] = t;
        }

        // Set the bones array to make the new skinned mesh renderer use the target skelleton
        smr.bones = bones;
        // Attach the new game object holding the new skinned mesh renderer to the target game object
        go.transform.parent = target.transform;
    }
}

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?

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.

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

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.

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,

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.

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.

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.

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. :frowning: I’ve definitely defined where the items can be equipped, and I’ve added weapon viewers, and they have prefabs and everything).

TP

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: Unity - Scripting API: Mesh.boneWeights )

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.

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…

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?

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

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.

.