- Home /
How do I Serialize a List of gameobjects without getting 3 duplicates/copies of each entry?
Unity 4, UnitySerializer. My game and saves and loads fine, but some of my lists end up three times longer after reloading with the same data repeating - seems to be only when they are List<> containing GameObjects.
If I save and reload, each time the lists will triple. I had to add a check to strip out the dulicates but I don't think it is a good idea because the save files are larger than they need to be (I assume anyway, I can't read the byte saved file).
How about you post some code so we don't have to use our $$anonymous$$d reading voodoo.
here is a test project Load it, press ESC, check the LogSeen list and it will be triple, press ESC again and it will triple. All the Lists of GameObjects will do the same thing.
There shouldn't be three here. I can't be sure if the save file has three copies or not but I suspect it does, that is what I want to avoid.
@originalterrox have you tried using LINQ and yourlist.Distinct().ToList() to create a new list without duplicates?
Yes, but that only fixes the list after it has been deserialized.
Answer by originalterrox · Apr 05, 2016 at 02:40 AM
One answer is to upgrade to Unity 5 and use unityserializer-ng which has fixed that issue.
Your answer
![](https://koobas.hobune.stream/wayback/20220612072248im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Implementing GetComponent or accessing children from SerializableObjects 1 Answer
UnityEngine.GameObject not marked as Serializable? 1 Answer
Best practice custom class with GameObject 0 Answers
How to Serialize and Deserialize a Dictionary Containing Gameobject and a Vector 0 Answers
XML Serialization problem 0 Answers