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.

The title may seem a bit confusing, so let me explain. I am using Json.Net and XNA. I have an entity class, that has a virtual update method. I also have a class named Monster, which inherits the entity method. It also overrides the update method, making the entity move.

So since I'm serializing a list of entities, and when I deserialize them, they are changed back into a regular Entity class. So how would I go about deserializing them back into their appropriate type?

A little more of an explanation, if you still find it a bit confusing, this time in code:

List<Entity entityList = new List<Entity>();

// Create a new monster (that inherits/derives entity)
Monster monster = new Monster(new Vector2(100, 100));

// Add it to our list of entities
entityList.Add(monster);

// Serialize the list of entities
string json = JsonConvert.SerializeObject(entityList);

// Now restore the entity list from the json
entityList = JsonConvert.DeserializeObject<List<Entity>>(json);

// ^ After the list has been restored, the original monster entity has been changed
// into a normal entity and will not do anything. How would I go about saving the type?
share|improve this question

closed as off-topic by Seth Battin, ClassicThunder, Josh Petrie Oct 20 '14 at 16:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Seth Battin, ClassicThunder, Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Possible duplicate: stackoverflow.com/questions/22465868/… –  Seth Battin Oct 20 '14 at 0:43
    
Thanks, that did it. –  user1772217 Oct 20 '14 at 0:52
    
Glad to hear it. Don't forget to search. :) –  Seth Battin Oct 20 '14 at 0:58

Browse other questions tagged or ask your own question.