Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am relatively new to XNA, and have started to delve into the use of the content pipeline. I have already figured out that tricky issue of adding a game library containing classes for any type of .xml file I want to read.

Here's the issue. I am trying to handle the reading of all XML content through use of an XMLHandler object that uses the intermediate deserializer. Any time reading of such data is required, the appropriate method within this object would be called. So, as a simple example, something like this would occur when a character levels:

public Spell LevelUp(int levelAchived)
{
    XMLHandler.FindSkillsForLevel(levelAchived);
}

This method would then read the proper .xml file, sending back the spell for the character to learn. However, the XMLHandler is having issues even being created. I cannot get it to use the using namespace of Microsoft.Xna.Framework.Content.Pipeline. I get an error on my using statement in the XMLHandler class:

using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;

The error is a typical reference error:

Type or namespace name "'Pipeline' does not exist in the namespace 'Microsoft.Xna.Framework.Content' (are you missing an assembly reference?)"

I THINK this is because this namespace is already referenced in my game's content. I would really have no issue placing this object within my game's content (since that is ALL it deals with anyways), but the Content project does not seem capable of holding anything but content files.

In summary, I need to use the Intermediate Deserializer in my main project's logic, but, as far as I can make out, I can't safely reference the associated namespace for it outside of the game's content. I'm not a terribly well-versed programmer, so I may be just missing some big detail I've never learned here. How can I make this object accessible for all projects within the solution? I will gladly post more information if needed!

share|improve this question
    
Any ContentImporter, ContentProcessor, or ContentWriters cannot be referenced at run time. –  Justin Skiles Sep 25 '12 at 12:47
add comment

3 Answers

You can't realistically ask people to download the entire XNA development framework just to run your game. And I'm pretty sure Microsoft won't allow you to just distribute the Content Pipeline DLLs willy nilly.

What you do to accomplish your goals depends on your answers to a couple of questions:

  1. Do you need to be able to serialize data to XML at runtime, or is this purely so you can make a level editor and plug a bunch of data into XML files that are to be read by your game at runtime (your XMLHandler.FindSkillsForLevel suggests that the latter is your case).

  2. Is it necessary for you to stream any data from a server that is meant to be deserialized, or can you assume it's all packaged in the game?

  3. If you do indeed need runtime serialization, is it absolutely required that you use XML? You may find it easier to map your data to JSON, which is easier to read and a little faster to emit and parse for many cases.

If you are only using the XML for defining your game data (and making level editors for you to use, you should split your solution up into 4 projects: Engine, Game, Editor, Content. Don't think of Engine as this fancy thing, it's just the common code shared between Game and Editor (see my answer here). Game contains game-specific code, all the presentation and special handling of level data and end-user UI. Engine can contain most of the code (AI, level logic, etc.) since you'll probably want to use the editor project as a catch-all for editing all sorts of data related to your game.

If you intend to stream XNB files to a desktop game, you may have to experiment with instantiating a ContentManager object using the constructor that takes a string. I haven't done this, so I don't know what the limitations are.

If you require runtime serialization/deserialization for playing your game outside of typical content pipeline use, you must handle your own serialization instead of relying on the content pipeline. The reflection API isn't too hard to use and understand, it's just tedious. And if you have to serialize your own stuff anyway, you may want to consider looking into JSON. It usually maps more intuitively to classes. A couple libraries to check out would be LitJSON for something lightweight, and JSON.Net for something more featureful and robust.

share|improve this answer
add comment

Content pipeline can not be referenced from project using .NET Framework 4 Client Profile. You can change this in (Right click on project -> Properties -> Application -> Target framework).

But can't you use normal content pipeline to build your XMLs and then load them as normal content?

share|improve this answer
add comment

The MSDN page for that namespace notes that it is only accessible from projects targeting Windows platforms. Double check that you are working with a standard XNA Game project and not an Xbox 360 one.

To check the target framework, select your project from the Solution Explorer then press F4 to access the Properties panel for that project. XNA Framework Platform should be listed as one of the properties and should have the value Windows as Xbox 360 and Windows Phone 7 projects do not have complete access to the content pipeline.

EDIT

In what project is this troublemaker 'using' statement, a Content, Content Pipeline Extension or standard Game project? References to the Content.Pipeline assembly are only available to the first two. Whichever it is, select that project in the solution explorer, right click "References" then "Add reference..." Under the .NET tab, scroll down to the very bottom and, if it is an applicable project, you should see the Microsoft.Xna.Framework.Content.Pipeline assemblies.

share|improve this answer
    
I have done as you suggested and it is definitely listed as being a Windows platform project, and just in case, I also checked the game library containing all classes meant to be deserialized into. Also Windows, so I do not think this is the issue. –  Zabby Mar 29 '12 at 5:45
1  
In what project is this troublemaker 'using' statement, a Content, Content Pipeline Extension or standard Game project? References to the Content.Pipeline assembly are only available to the first two. Whichever it is, select that project in the solution explorer, right click "References" then "Add reference..." Under the .NET tab, scroll down to the very bottom and, if it is an applicable project, you should see the Microsoft.Xna.Framework.Content.Pipeline assemblies. –  DaveStance Mar 29 '12 at 6:10
    
@ZabbyWabby, hope that helped you out, if it did, mind accepting it as an answer? I'll edit that suggestion into the OP. –  DaveStance Mar 29 '12 at 6:59
    
The used project is the main game project, and I already have added the reference you speak of. Currently, the content project uses this reference without any issue. –  Zabby Mar 29 '12 at 11:50
add comment

Your Answer

 
discard

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.