Add the mesh, not the textures

Originally posted to Shawn Hargreaves Blog on MSDN, Friday, November 3, 2006

Here's a common mistake for people new to the Content Pipeline...

If you have a mesh file that references a bunch of texture files, and you want to use this with XNA, you only need to add the mesh to your C# Express project. When we build the mesh we will notice what textures it references and automatically go build those too, so there is no need to explicitly add the textures to your project.

And for bonus points, here's a common gotcha when adding content files to C# Express...

By default, when you choose Add / Existing Item, pick a mesh file, and then click the Add button, if that mesh isn't already inside your project folder, C# Express will automatically copy it into your project folder. This can give surprising results for two reasons:

- If you then go back and edit the original mesh, your changes will be ignored because C# is referencing its own copy of your file.

- If the mesh references textures, those won't have been copied, so the mesh won't be able to find its textures in the relative path where it is expecting them to be.

There are two ways to prevent this problem. Either put your mesh and texture files inside the project folder to start with, so C# Express will not try to copy them, or explicitly tell it not to copy. To do that, in the "Add Existing Item" file selector, rather than clicking the Add button, click the little down arrow at the right of the Add button, and select "Add As Link".

Blog index   -   Back to my homepage