3 min read

Extending the Content Pipeline - Part 1

Introduction

In this tutorial, we are going to make a simple extension to the content pipeline. In everything that we have done up until this point when we use the content pipeline, we have used only the built-in stuff. In this tutorial, we will go through the process of creating our own extension to the content pipeline from the ground up. We will use it to read in information about a level for a game. The idea with this (in fact, the idea with the content pipeline as a whole) is that your level designer (or another artist, if it is a different kind of asset) can use a completely separate program to create your levels, like a level editor, and the programmer can easily read in the level information in an easy manner. In fact, we will see that after our content pipeline extension is complete, we will be able to say:

Level level = Content.Load<Level>("level14");

Creating an entire content pipeline extension from the ground up is actually a fair amount of work, especially if the information in the file is fairly complicated. Because of all of this work, this tutorial is quite long. In fact, I think it is the longest tutorial on this website. I’ve broken it up into eight parts to make it easier to go through.

This is a fairly advanced tutorial, and I wouldn’t recommend going through it if you are still just getting started with XNA. However, at a bare minimum, you should have gone through the tutorial on managing content in XNA}, as well as read through and understood the information in the content pipeline tutorial.

At this point, I think that it is also worth pointing out that the content pipeline is not available to the end-user. For example, I once made a program that allows you to make animations with a 3D model. The program allows the user to access the content pipeline to load in models from a file (I didn’t want to have to parse all of those files on my own!). However, since redistributable for XNA games does not contain the content pipeline, a normal user couldn’t use the program unless they installed XNA Game Studio, which for what I was doing, wasn’t a big deal. But just keep in mind that most end users won’t have access to the libraries that deal with the content pipeline. Users will not usually need access to the content pipeline, though. Usually, when the programmer compiles the game, all of the assets are pushed through the content pipeline and stored in a .xnb file (called a “compiled asset”), which is then distributable and can be accessed even without going through the content pipeline.

The level information that we will be using will be pretty simple. Our level will simply be a grid of numbers. You are more than welcome to load different or additional data with your level, but I would recommend completing this tutorial as it is before trying to make too many changes. Content pipeline extensions can be tricky, and when you have bugs in it, it usually gives you cryptic information on what went wrong, so it takes extra work to debug. In fact, the first time that I was demonstrating content pipeline extensions in front of a group of people, it failed miserably. I don’t really know what I was doing wrong, but nothing seemed to be working. So be careful as you are reading through this tutorial to reduce the number of bugs you make because it can be a little tricky. But it can really be worth the trouble!

Also, because this tutorial is pretty big, and because it might be easy to make a mistake, I’ve uploaded my entire project for this tutorial below. This way, if you run into trouble, you can use it as a reference.

ContentPipelineExtension.zip