Home > XNA > XNA 3.0 Content Pipeline

XNA 3.0 Content Pipeline

January 1st, 2009 Leave a comment Go to comments

I spent all day researching the XNA Content Pipeline in XNA 3.0. The MSDN documentation is a little sparse/dense on how things work together; so I pulled together some resources that I found helpful when trying to understand it.

There’s 4 main components in the Content Pipeline: Importers, Processors, Writers, and Readers. Read the 2nd point to understand how they work together or go through the tutorial in my 1st point to get your hands dirty. The 3rd point is another tutorial to help you understand creating a new game asset from start to finish.

1. Nick Gravelyn wrote a brief tutorial on using XML to describe content here. It uses the default Content Processor and Importer from XNA for XML and then it creates custom Readers and Writers.

I followed along and got stuck on the project Reference part. There are two sets of references, one for the code and the other for the Content sub-folder in an XNA project. I didn’t realize it until I looked very closely at my project. Since I overlooked the Content references I got the following error while trying to build the CrateSprite XML asset.

Building CrateSprite.xml -> C:\Documents and Settings\Paul Solt\My Documents\Visual Studio 2008\Projects\XMLProject\XMLProject\bin\x86\Release\Content\CrateSprite.xnb
Content\CrateSprite.xml(3,10): error : There was an error while deserializing intermediate XML. Cannot find type "XmlContentSampleShared.Sprite".

The problem is that the reference to the SpriteContentWriter.cs and the Sprite.cs classes are missing (They are in separate projects). To fix it all you need to do is to include the project containing the Writer, which has a reference to the shared project containing the Sprite class. My Content build process just didn’t know how to process the CrateSprite.xml file. Here’s a picture of the projects and the highlighted references (Right click and add Reference -> Projects).

Visual Studio 2008

Visual Studio 2008

2. Shawn Hargreaves also recently posted about the basics of the Content Pipeline here. He pulls apart the different steps involved so that you can understand the entire content pipeline using colors. (Shawn Hargreaves is the expert on XNA)

He describes why the Content Readers and Writers are separated. Writers help create the .xnb (XNA Binary) format, while readers read in the compiled .xnb format that is packaged with an XNA game. A distributed game doesn’t need the Content Writers, so you can separate that functionality into a separate project, while keeping the Content Readers associated with the Game project that gets distributed.

3. Another tutorial I looked into is from Ziggy. He creates a custom game asset (bounding box) and the associated Content Processor, Importer, Reader, and Writer. This tutorial helps drill in the fact that you’re creating new content and having XNA interpret it and build it into an asset that your game can load. Very powerful stuff.

I incountered a few differences in the tutorial, since it was written using XNA 1.0, but overall you shouldn’t have too many issues following it. (There is a converted XNA 2.0 project for the tutorial if you get stuck)

Update: Here’s another useful blog post from Eli Tayrien with a collection of links for the XNA Content Pipeline.

Categories: XNA Tags:
  1. Kevin Smeltzer
    May 7th, 2009 at 17:06 | #1

    Thank you for clearly showing us how to do this.
    I just spent the last hour figuring out what my code wasn’t working.
    All of the other tutorials I read were something along the lines of:

    “1. Link your content file to your main game project”
    “2. Link your library to your extension”
    “3. Do not, I repeat DO NOT link your main project to your extension under any circumstances!!!!”
    “4. Link your main project to your extension”
    “5. Link your extension to your library”
    “6. Link content to library main content libary extension”

    Who would have guessed it only took one IMAGE to show everyone how to do it?

  2. May 19th, 2009 at 12:07 | #2

    You’re welcome!

  3. May 21st, 2010 at 10:35 | #3

    Thankyou for this! I had the same issue as the above poster. I imported all the required projects, added all the references, but I forgot to add the reference under the Content section in the main project! D’oh!!

    Thanks again =)

  4. May 26th, 2010 at 13:20 | #4

    No problem

  1. No trackbacks yet.