Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my problem is :

If I load 2 models ( the same model zombie ) and give them the same effect I got the following error :

        for(int i =0 ; i<2 ; i++)
            dwarfModel[i].model = Content.Load<Model>("Models//dwarf//dwarfmodel");
            dwarfModel[i].effect = Content.Load<Effect>("Models//dwarf//skinFX");
            dwarfModel[i].setEffect(camera , game);
            dwarfModel[i].intializeChrachterController(new Vector3(0, 0, 0), 20, 10, 2000, 2000, 80, 40);


enter code here

enter image description here

share|improve this question

closed as off-topic by Josh Petrie Jan 22 '14 at 19:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

One of the meshes in the model is probably using a different Effect-type i.e. SkinnedEffect which cannot be cast into a BasicEffect. – Aaron Kabashi May 27 '13 at 14:48
Aaron Kabashi , so what is the solution ?? I must use the same effect ?? that's problem occured when I make 2 models of the same type , i.e Zombie share the same effect , but if I load monster.x and zombie.x and use the same effect then no problem !! – Mohammad Ahmed May 27 '13 at 15:36

When you try to call the Effect property of your ModelMeshPart you get an Effect instance and Effect is the base class for all effect. So you can't cast an Effect instance to a BasicEffect because BasicEffect inherits from Effect.

Furthermore you don't need to cast it to a BasicEffect.

Your line:

BasicEffect oldEffect = (BasicEffect)part.Effect;

Should be:

Effect oldEffect = part.Effect;
share|improve this answer
Takumi I will try in a moment – Mohammad Ahmed May 27 '13 at 13:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.