Problems serializing objects
toreau
✭
I've read the documentation here, and as I understand it, PUN is able to serialize fairly "complex" data types out of the box. I have a problem, however, when an object derived from this class fails to serialise;
[code2=csharp]using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Item {
public string ID = "";
public int createdEpoch = 0;
public string name = "";
public string description = "";
public string iconName = "";
public int maxInSlot = 0;
public Dictionary<string, int> craftingRequirements = new Dictionary<string, int>();
public float craftingTime = 0.0f;
public int cookingPoints = 0;
public int maxCookingPoints = 0;
public Dictionary<string, int> cookingResultsIn = new Dictionary<string, int>();
// Constructor
public Item () {
ID = System.Guid.NewGuid().ToString();
createdEpoch = (int)(System.DateTime.UtcNow - new System.DateTime( 1970, 1, 1 )).TotalSeconds;
}
}[/code2]
The class that derives from this class, the one that needs to be serialized, only sets its name, description and iconName. It doesn't add anything.
As far as I can tell, the only "advanced" type here is the Dictionary, but according to the documentation PUN should be able to serialize that...?
Am I missing something?
UPDATE: Even if I remove the Dictionary variables, it won't work.
[code2=csharp]using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Item {
public string ID = "";
public int createdEpoch = 0;
public string name = "";
public string description = "";
public string iconName = "";
public int maxInSlot = 0;
public Dictionary<string, int> craftingRequirements = new Dictionary<string, int>();
public float craftingTime = 0.0f;
public int cookingPoints = 0;
public int maxCookingPoints = 0;
public Dictionary<string, int> cookingResultsIn = new Dictionary<string, int>();
// Constructor
public Item () {
ID = System.Guid.NewGuid().ToString();
createdEpoch = (int)(System.DateTime.UtcNow - new System.DateTime( 1970, 1, 1 )).TotalSeconds;
}
}[/code2]
The class that derives from this class, the one that needs to be serialized, only sets its name, description and iconName. It doesn't add anything.
As far as I can tell, the only "advanced" type here is the Dictionary, but according to the documentation PUN should be able to serialize that...?
Am I missing something?
UPDATE: Even if I remove the Dictionary variables, it won't work.
0
Comments
-
Possible you missed implementation of type serialize/deserialize procedures and type registration as described in 'Custom Types' section of documentation you mentioned.
If you want serialize derived class then you should register exactly that class.0