Intermediate Serializer + Farseer

Topics: Developer Forum, Project Management Forum, User Forum
Jan 14, 2010 at 11:20 PM

O hai.
I want to apologize beforehand if this is the wrong place to post this.

I'll try keep it short and straightforward.

I'm making a level editor for a XNA game that saves its level using a IntermediateSerializer, but I'm having great problems getting it to work.
I'm using C# + XNA 3.1 and Farseer 2.1.1

Here are the Save and Load functions respectively:

public void Save(string zFilePath) {
   FileStream tFileStream = new FileStream(zFilePath, FileMode.Create);

   XmlWriterSettings tSettings = new XmlWriterSettings();
   tSettings.Indent = true;

   using (XmlWriter tXMLWriter = XmlWriter.Create(tFileStream, tSettings)) {  
     IntermediateSerializer.Serialize(tXMLWriter, this, null);


public static Level Load(string filename) {
   FileStream tFileStream = new FileStream(filename, FileMode.Open);
   Level tLevel = null;

   XmlReaderSettings tSettings = new XmlReaderSettings();

   using (XmlReader tXMLReader = XmlReader.Create(tFileStream, tSettings)) {
     tLevel = IntermediateSerializer.Deserialize<Level>(tXMLReader, null);


   return tLevel;

Although I had to remove the [ContentSerializerIgnore] for the Geoms body for this to work (also removed it on all other members on a "just in case" basis, together with adding set{} to all get{}).

For an example of a level saved like this see
(It's over 150 lines long, feelt a bit unnecessary to post it in it's entirety here)

Anyway, onto the main problem: Collisions doesn't work, although gravity is handled and everything can be drawn without problem. Two Geoms/bodies created outside the editor trigger a collisions with a PhysicsSimulator created in the editor, but they still phaze through each other, while geoms/bodies created in the editor won't collide at all.

Right now I feel like I'm just fumbling in the dark, I can't figure out anything more to try.

Right now my best theory is that I need to do my own XmlReader, because right now the Geoms and Bodies aren't made through a Factory. If so is the case, I humbly ask for a link to a tutorial to do so :) .

So, any ideas what I could be doing wrong?

Jan 17, 2010 at 1:31 PM

Just a guess, but make sure that the collision group and collision category (all collision filtering properties actually) gets serialized. If you are using the distance grid, the grids also needs to be in place for collision to work. Try switching to SAT narrow phase collider, just to see if works.

Jan 18, 2010 at 3:11 AM

The collision group and category etc was all serialized correctly, but the grid size wasn't. I first tested to just add GridCellSize to be serialized, but it didn't help.

Then I tested to run the geom through a GeomFactory again after reading the level, and the factory apparently worked it's magic because everything started working (yay!), but only when using a physicssimulator created outside the editor. From what I can see an PhysSim from the editor and a 'normal' PhysSim are identical, so what could be wrong there?