Problem while saving gameobjects' data in XML file
I am trying to save gameobject's data in XML file but in XML file, I am only getting the last value from the List instead of two different values. I have instantiated two tooltips under different two different gameobjects and I am storing those instantiated tooltip's in list. When I print the text of the tooltip, I am getting two different values but when I try to save those two values in XML file, I am getting the text value of the last instantiated tooltip twice in XML file.
Below is the code.
public ItemEntry newItem = new ItemEntry();
public ItemDatabase itemDB;
ObjectSpawnManager ObjectSpawnManager;
private void Start()
{
ObjectSpawnManager = GetComponent<ObjectSpawnManager>();
}
public void SaveFeedback(GameObject parentGameObject)
{
foreach (GameObject go in ObjectSpawnManager.iconTooltipList)
{
Debug.Log(go.GetComponentInChildren<TMPro.TextMeshPro>().text);
newItem.toolTipText = go.GetComponentInChildren<TMPro.TextMeshPro>().text;
itemDB.list.Add(newItem);
}
XmlSerializer serializer = new XmlSerializer(typeof(ItemDatabase));
FileStream stream = new FileStream(Application.dataPath + "/Feedback Solution/feedback_data.xml", FileMode.Create);
serializer.Serialize(stream, itemDB);
stream.Close();
}
public class ItemEntry
{
public string toolTipText;
}
public class ItemDatabase
{
public List<ItemEntry> list = new List<ItemEntry>();
}
Below is the output from XML file:
<?xml version="1.0"?>
<ItemDatabase xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<list>
<ItemEntry>
<toolTipText>Remove</toolTipText>
</ItemEntry>
<ItemEntry>
<toolTipText>Remove</toolTipText>
</ItemEntry>
<ItemEntry>
<toolTipText>Remove</toolTipText>
</ItemEntry>
</list>
</ItemDatabase>
Can someone please help me with this?
Your answer
![](https://koobas.hobune.stream/wayback/20220613021512im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to output a List of Strings to canvas text? 0 Answers
How to output a List of Strings to canvas text? 0 Answers
how to get component of array in unity 0 Answers
"Failed to load window layout" Error 5 Answers
Unity installation error, DISM 87 0 Answers