- Home /
Scene Variable Serialization issues on crash, save etc.
I have a script (Monobehaviour) with different List for objects I am saving. My custom editor handles these objects as a pseudo scene manager. The variables save and serialize just fine, however if unity crashes or the library has to rebuild, it seems I have to reload references and re-enter information into my variables again as if unity lost the serialization data of the Monobehaviour, even if the scene had previously saved. This normally would not be an issue, however I use many instances of the script and losing all the data is not an option.
Question: Should we trust the unity serialization of monobehaviour variables or should we roll our own option; and if we roll our own, how would we store transform, gameobject, scene references since Unity GUID changes on per scene session?
Pseudo Code Clarification
[serializable]
public custom_class : MonoBehaviour
{
public List<int> int_data;
public List<string> string_data; // When unity crash all modified strings lost, even after a save?
public List<Transform> transform_data; // How to reload reference from data file ie: XML?
// etc
}
Answer by darkForester · Sep 10, 2012 at 07:13 PM
Well I sorted it out myself. I decided that I would custom serialize my own scene values into xml and then on the chance there was a crash, the variable data store would repopulate itself.
Using the path from GameObject I would find it, and then GetComponent(T) the type I needed back for reference.