- Home /
Problems with the XML Serializer
Hi !
I've read the tutorial explaining how to use the XML Serializer on the wiki here : http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer
But actually, it isn't explaining anything.
I want to know whether should I make a using UnityEngine statement and inherit from MonoBehaviour in the Monster class to be able to add the script to a game object.
Thanks in Advance
Answer by Xarbrough · Jan 06, 2016 at 11:02 PM
XML Serialization and turning classes into MonoBehaviours are two different things. First, I wouldn't serialize a MonoBehaviour to XML, usually you only want to save some specific set of data. So maybe you want to serialize a PlayerStats class to XML, but then have a Player MonoBehaviour that lives as a scene object on a component and does things.
Or what are you trying to do?
I am trying to save a sprite's tag and position to X$$anonymous$$L. It doesn't have any $$anonymous$$onoBehaviour class. But I can't add a script to game object if it is not a $$anonymous$$onoBehaviour class.
public class $$anonymous$$ySpriteComponent : $$anonymous$$onoBehaviour
{
public SpriteData data;
[System.Serializable]
public class SpriteData
{
public string tag;
public Vector3 position;
}
}
I would have a scene component ($$anonymous$$onoBehaviour) that contains a reference to some sort of data, which you store and load depending on your needs. If you don't know what I'm talking about, this tutorial might help: data persistence tutorial
So, this will replace the $$anonymous$$onster class in the tutorial above ?
And I think that this way it's not going to the use the X$$anonymous$$L Serializer. It isn't mentioned anywhere in the script.
I mean, after I write the 2 classes as mentioned in the link above, what should I do to actually save data to X$$anonymous$$L ? Add the $$anonymous$$onster class to an object ? But I can't because it doesn't inherit from $$anonymous$$onoBehaviour. Also, how can I call the Save function? It shows me a red line under Path when I call it from another script.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Deserializing data with XML Serializer 0 Answers
Distribute terrain in zones 3 Answers
xml parsing error 0 Answers
ScriptableObject+XmlSerializer=sad 2 Answers