unhandled exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll,

First off, I posted this on the old thread and realized that isnt smart. My apologies. But here is my situation need 3D animation in my game and I found this thread. Tutorial: How to get XNA's SkinnedSample working with MonoGame
Now, I think I have done everything in the right way, but I am getting an error. An error.regarding this line AnimationClip clip = skinningData.AnimationClips[“Take 001”];. The error message states: “An unhandled exception of type ‘System.Collections.Generic.KeyNotFoundException’ occurred in mscorlib.dll, additional information: the given key is not present in the library.” When i keep my mouse over clip in the debug it tells me it is null.

The model i have does build in the pipeline with your processor, and the namespace SkinnedModel is also showing up nicely.So does anyone possible have any idea what i am doing wrong?

Thanks in advance, and you have already helped me a great deal. Once again sorryfor bumping the old post.

Jeromer

The exception states pretty clear what the problem is. “Take 001” is not in the AnimationClips dictionary. You can see what is in there in the debugger.

Thanks for the reply.

But i forgot to mention that i changed the take 001 to ArmatureAction. As that is the armature for the model. From my understanding of the code, in that string one writes the armature needed. Or have i completely missed the meaning of that. But ill have a look. Thanks!

I don’t understand what you’re trying to do.

The AnimationClips library contains animationClips which are basically a list of KeyFrames. An armature is not an animationclip… And you’re not writing “in that string”, you’re writing the dictionary value corresponding to a specific key.

Use the debugger to see what the named clips are actually in skinningData.AnimationClips. This is likely just a case of having the name not quite right.

Thanks for the responses, and sorry it has been unclear. I am still a giant beginner in gameDev and monogame.
But I understand what you guys mean by writing the value to the specific key. And indeed the armature is indeed not a animationclip. I just need to figure out what I can actually write in there or what the named clips are in the SkinningData.AnimationClips. I honestly don’t know where to find it then. And I know that keyframes can be inserted in blender. Do you guys by any chance know what keyframe I need.

Thanks everyone,

Jeromer

When it breaks on that line in the debugger, you can dig down into the dictionary object in the Watch window or just by hovering the mouse over the AnimationClips text in the editor window. Digging into the keys in the dictionary, you can see what values are actually in there.

Thanks for the reply,

But I am pretty sure I am still doing something wrong. I try to dig into the dictionary object in the Watch window. When I hold my mouse over AnimationClips it says count =1. So in the Watch window i fill in skin.AnimationClip[“0”] it gives me the same error. I expect that I am still doing something wrong but I honestly have no clue what. Could someone possibly help me a bit further again?

Once again thanks for the replies everyone.

Jeromer

You can expand the Items field (I’m not 100% sure that’s the name, but should be something like that), check what’s in there at the first place and check its key. That’s the string it’s stored under in the Dictionary.

“0” is a string. That means you’re looking for the value stored under the string “0”. You can use skin.AnimationClip[0] to actually get the first item in the dictionary.

First off, thanks for the response.

I’ll try this, need to figure out how. But for the second thing you told me, it gives me the error:cannot convert from int to string.

When the debugger has stopped on that line, hover the mouse over AnimationClips, and then move it down over the little drop arrows.

Thanks,

Now I found the key I needed to put in. Didn’t even know I could go through all those nice little drop arrows. I can progress with it now. Need to make the animation and model to be able to draw on a position I want it to draw. Nice next challenge.

Once again thanks to everyone.You have helped me a lot.

Jeromer

Hello everyone, I am back.

Sorry for another question related to this. I figured out the name after your help. Thank you for that. I draw it in the way it is said that you need to draw it. By:

         // Render the skinned mesh.
        foreach (ModelMesh mesh in currentModel.Meshes)
        {
            foreach (SkinnedEffect effect in mesh.Effects)
            {
                effect.SetBoneTransforms(bones);

                effect.View = view;
                effect.Projection = projection;

                effect.EnableDefaultLighting();

                effect.SpecularColor = new Vector3(0.25f);
                effect.SpecularPower = 16;
            }

            mesh.Draw();
        }

Where my projection is the camera projection, and the view is my camera view. I have also added a effect.world.

I did this becasue the models we had, these are without animations, were drawn like this:

/* Method for drawing a model mesh. It also takes in account the rotation for
 * cases such as enemies facing certain directions. The Vector4 is used to 
 * both hold the position and the rotation. */
   public void DrawModelMesh(string modelName, float rotation, Vector3 position)
   {

    Model model = DOOM.AssetManager.GetModel(modelName);

    //Creates an array of Matrices for each parent bone
    Matrix[] transformMatrix = new Matrix[model.Bones.Count];

    //Fills the arrays of the previously made array of Matrices with the matrix information of each bone
    model.CopyAbsoluteBoneTransformsTo(transformMatrix);


    foreach (ModelMesh mesh in model.Meshes)
    {
        //Seperately calculates the world matrix for each parent bone in the Matrix array
        Matrix worldMatrix = transformMatrix[mesh.ParentBone.Index] * Matrix.CreateRotationY(rotation) * Matrix.CreateTranslation(position);

        foreach (ModelMeshPart meshPart in mesh.MeshParts)
        {
            BasicEffect effect = (BasicEffect)meshPart.Effect;
            effect.World = worldMatrix;
            effect.EnableDefaultLighting();
            effect.View = camera.View;
            effect.Projection = camera.Projection;
            DrawIndexedPrimitives(effect, meshPart);
        }
    }
}

 /* Method fo drawing indexed primitives. As of now, solely used for drawing models. Perhaps
 * it is useful in the future for drawing other indexed meshes. */
public void DrawIndexedPrimitives(BasicEffect effect, ModelMeshPart meshPart)
{
    foreach (EffectPass pass in effect.CurrentTechnique.Passes)
    {
        pass.Apply();
        graphicsDevice.SetVertexBuffer(meshPart.VertexBuffer);
        graphicsDevice.Indices = meshPart.IndexBuffer;
        graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, meshPart.VertexOffset, meshPart.StartIndex, meshPart.PrimitiveCount);
    }
}

Any advice on how to rewrite the drawing method. Thus the animated model is placed on the positions we have given it but that it is animated? Any help is appreciated. I wasn’t even able to draw the model without help from you guys. So you guys are a lifesafer for me.

Once again thanks:) and any help is appreciated

Jeromer