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

So far, in my rhythm game, I've been using XNA's Content Pipeline for loading static resources in my app (videos, sound effects, etc). However, down the road I'd want to allow users to create their own themes, as well as making custom notecharts for whatever songs they'd like to play. Is there any way to load say, a Texture2D or Video object, from disk without using the Content Pipeline, given a file path to the resource?

EDIT: Even thought this is XNA, I'm targeting Windows only (no Zune, WP7, or Xbox 360).

share|improve this question
up vote 4 down vote accepted

Use the Texture2D.FromFile method; for the first parameter, give it your GraphicsDevice which is a property of the Game class (so from within a method of the Game class, just use this.GraphicsDevice).

Unfortunately only Texture2D objects can be loaded this way; a Video object is not so easy to load.

share|improve this answer
Dang, loading audio and video at runtime are going to be critical in my app down the road, so this is bad news. – ThatsGobbles Oct 5 '10 at 17:36
Not all hope is lost though! Look at the second answer to the linked question; looks like you can compile and run a video or audio at runtime, with XNA 3.1.… – Ricket Oct 5 '10 at 18:27
@Ricket Yeah, I can't have users be forced to download GS just to be able to compile these, so I'm still stuck. I'm trying to look into the DirectShow VideoPlayer, but it's old and finicky. – ThatsGobbles Oct 6 '10 at 12:55
But... they need to have XNA installed whether it's 3.1 or 2.0, right? What's the difference? – Ricket Oct 6 '10 at 14:45
The XNA Runtime is always needed, yes (if I recall correctly). However, that MSBuild method requires the entire Game Studio to be downloaded on the user's computer (and GS 4.0 is about a 400 MB ISO). – ThatsGobbles Oct 6 '10 at 14:50

It's entirely possible to run the content build process at runtime using MSBuild. The following sample shows you basically how to do it: This particular example uses windows forms, but there is nothing preventing you from doing the same thing in an actual game.

The big problem is that the content pipeline assembly (which is where all the processors/importers/build tasks necessary for building are) is not included in the XNA Framework redistributable. This means that in order to actually create and/or load custom content your users would need to install whatever version of XNA Game Studio your game was built with. They would never need to actually use any of the software included in it, but they would need to install it. Depending on your game and who you expect to be creating and using custom content this may or may not be acceptable.

share|improve this answer
If only it didn't require installing XNA GS on the user's computer, this would have been perfect. – ThatsGobbles Oct 6 '10 at 4:07
It's certainly unfortunate. I remember seeing rumblings some time ago (years) about the XNA Team wanting to get the Content Pipeline stuff into the redist, but it hasn't happened in the last few versions and it seems unlikely to happen soon given their current focus on non-PC platforms where the pipeline won't run anyway. – Flintlock Oct 6 '10 at 15:11
Makes sense, although yeah, it kinda sucks for PC-only XNA games. – ThatsGobbles Oct 6 '10 at 23:47

Some of the content processors expose classes which do a lot of the heavy lifting, e.g. take in a Stream and produce an intermediate object (like the data necessary to construct a mesh, but not an actual Mesh object). You may be able to do some additional processing to transform the intermediate object into the final object that you want to consume. Some of those classes may actually even spit out the final object for you. It varies by the type of content. I suggest digging through the content processors for the relevant content types and see anything useful is exposed. You may have to rewrite some bits yourself (Reflector is your friend), but it could be worth the effort if you really don't want to use "precompiled" assets.

share|improve this answer
Do you have any recommendations and/or links to examples? It seems like the only media type I'm lacking the ability to import now is video, and IIRC it's one of the two that is considered infeasible to load manually. – ThatsGobbles Oct 8 '10 at 18:09

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.