Game Won't Compile when Using my Manager?

Started by
1 comment, last by hrmmm 10 years, 8 months ago

So I am having this issue with a line of code claiming that I am referencing a different effect that is not basiceffect?

foreach (ModelMesh Mesh in Model.Meshes)
foreach (BasicEffect ES in Mesh.Effects)
Textures[i++] = ES.Texture;

Those are the lines of code that fail for me, I have a manager that spawns 5 buildings and calls that texture loading method right there 5 times. For some reason though I get the error: Unable to cast object of type 'Microsoft.Xna.Framework.Graphics.Effect' to type 'Microsoft.Xna.Framework.Graphics.BasicEffect'.

Does anyone have a fix for this?

Advertisement

Do a foreach Effect instead of BasicEffect. Then cast to BasicEffect inside the foreach block.

You're trying to convert the property to a type its graph doesn't support so it bombs. This is done by first assigning an object of the type you want to extract to the property before you do your foreach.

Edit: Saw this was on compile. This is strange. With casting as long as your "box" gets bigger, and not smaller, it's fine. Do you have VS set to fail on warn?

This topic is closed to new replies.

Advertisement