This is my class:
namespace myclass
{
[Serializable]
public class BasicGameObject : GameObject
{
protected Shadow shadow_ = null;
protected bool shadow_enabled_ = false;
protected Dictionary<string, AnimationManager> animations_ = new Dictionary<string, AnimationManager>();
protected Dictionary<string, string> loaded_textures_ = new Dictionary<string, string>();
protected string current_animation_;
protected int frame_width_;
protected int frame_height_;
//Costructor and other methods
//...
[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
Console.WriteLine("BasicGameObject");
foreach (KeyValuePair<string, AnimationManager> anim in animations_)
{
animations_[anim.Key].Reload(Loader.GameObjectTexturesList[loaded_textures_[anim.Key]]);
}
}
When I deserialize this object, I need it to reload every texture stored in "animations_".
If I put a breakpoint on Console.WriteLine("BasicGameObject");
, and click on anim
, the debugger shows me that anim's Count
is at 0, but every other variable has the right value. (I'm sure that while saving, it wasn't at 0)
What's the problem?
How I load the object (SERIALIZATIONOBJECT_
just contains a list of BasicGameObject
):
IFormatter formatter = new BinaryFormatter();
SERIALIZATIONOBJECT_ = (SerializationObject)formatter.Deserialize(stream);
stream.Close();
After this, (and after OnDeserialized
call!), If i do some test, I see that anim
of my object, has the right value. Why here and not inside "OnDeserialized"?
I just want to note that before I was using the same identical function that now is in OnDeserialized
without the attribute, but just as a function, and I was calling it after deserialization. I saw the possibility di automatize it and I thought it was good. Maybe it hides something.