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

I'm trying to retrieve the names of the texture files (or their locations) on a mesh.

I realize that the texture file name information is not preserved when the model is loaded.

I've been doing tons of searching and some experimenting but I've been met with no luck. I've gathered that I need to extended the content pipeline and store the file location in somewhere like ModelMeshPart.Tag.

My problem is, even when I'm trying to make my own custom processor, I still can't figure out where the texture file name is. :(

Any thoughts? Thanks!


Okay, so I found something kind of promising. NodeContent.Identity.SourceFilename, only that returns the location of my .X model. When I go down the node tree he is always null. Then there's the ContentItem.Name property. It seems to have names of my mesh, but not my actual texture file names. :(

share|improve this question
Mind if I ask why you're doing this? (I.e. why you need the name of the texture file.) – Olhovsky Jun 2 '11 at 17:23
I'm converting an old .NET 1.1 app that used MDX to XNA. In that app, the texture represents a part on a vehicle. When the user clicks the texture (or the part on the vehicle), it uses the texture's name to figure out what part it is. And based off the texture name, it loads more information on the part. I'm not sure of a better way to do this, so I was just trying to do the same in XNA. Better ideas are especially welcomed. :) – Ashley Grenon Jun 2 '11 at 17:31
@townsean: A better way of doing it would be changing it to not use the texture name as part of the program state. You should never use strings for passing around state. – BlueRaja - Danny Pflughoeft Jul 3 '11 at 6:32

Alright, I think I figured it out. Maybe not the best solution (so I would still appreciate other answers ;) )

public override ModelContent Process(NodeContent input, ContentProcessorContext context)
    ModelContent model = base.Process(input, context);
    foreach(ModelMeshContent modelMesh in model.Meshes)
        foreach(ModelMeshPartContent meshPart in modelMesh.MeshParts)
            MaterialContent materialContent = meshPart.Material;

            foreach(var texture in materialContent.Textures)
                if(texture.Value != null)
                    meshPart.Tag = texture.Value.Filename;
    return model;

The Tag property of my ModelMeshPart the file points to the .xnb file in the output directory.

share|improve this answer
+1 for preventing Community ♦ from bumping this question again. – aaaaaaaaaaaa Dec 29 '11 at 20:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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