1
\$\begingroup\$

I am having some trouble serializing/deserializing in a little game I am doing to teach myself monogame.

Basically, I am using the gamestatemnanagement resources common to monogame (screen manager etc). Then I am serializing my screen manager component and all associated screens in the OnDeactivated method:

 protected override void OnDeactivated(Object sender, EventArgs args)
    {
        foreach (GameplayScreen screen in mScreenManager.GetScreens())
        {
            DataManager.SaveData(screen.Level.LevelData);
        }
        mScreenManager.SerializeState();
    }

The Save data bit is to do with something else.

Then I then override OnActivated to de serialize

    protected override void OnActivated(Object sender, EventArgs args)
    {
        //System.Diagnostics.Debug.WriteLine("here activating");
        mScreenManager.DeserializeState();
    } 

However, when this runs it just loads a blank screen - it goes into the game initialize and the game draw method, but doesnt go down into the screens initialize or draw methods.

I have no idea why this might be - any help would be greatly appreciated. I am not the only one who has encountered this - I found this post also - https://monogame.codeplex.com/discussions/391117

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I am willing to bet that you need to mark your model's tags (the ones you want anyway) with the "Serializable" Attribute tag.

http://msdn.microsoft.com/en-us/library/system.serializableattribute(v=vs.110).aspx

I can't find anything to prove otherwise, but I am very doubtful that DeserializeState has no arguments, you likely need to point to what is being deserialized.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .