how to save a lot of character data?

I am making a Simulation Game that you can buy and foster a lot of insects which have their own data(for example: hunger value ).
so I want to save these bugs’ data, I have found a method using
" PlayerPrefs.SetString(“bug”,JsonUtility.ToJson(“the bug’s class”)); "
but that means every insects has a own file (I need to use a loop to save every bugs’ data)
and I have to record how many bugs are and what kinds of insects it is?
then , when I load this game I have to instantiate every bugs(what kinds ,which prefabs ,how many?)
and give them their own data.
It’s very complex .
Does anyone have a better idea?
Thanks in advance.

Hi @dnwsaa58

What you need is serialization - Start reading about serialization in Unity - Search / google for: “unity serialization tutorial” and you’ll find many good videos / tutorials.

You could use JsonUtility to serialize/deserialize your data to JSON, like you already do, but instead of single bug, you can create a class that contains bugs and other data related to bugs, and serialize that to JSON instead.

Also, instead of PlayerPrefs, you can also choose to use C# File or StreamWriter/Reader classes to write to / read from text files.

You could also use C# Binary serialization (BinaryFormatter - edit: binary formatter is no longer consider safe, so avoid it) to serialize your data to non-(human)readable format…

There are many good questions and answers here in Answers on this topic.