Sign in to follow this  

Game Won't Compile when Using my Manager?

Recommended Posts

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?

Share this post

Link to post
Share on other sites

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?

Edited by hrmmm

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this