Some help with saving and loading in Unity

I’m reading up on how to save and load in Unity, and I’m having a little trouble understanding it. Thus far, I understand that data must be serialized. But let’s say you have a class called “Enemy,” and that class stores variables for the enemy object’s position, rotation, and health. How do you serialize this class for multiple enemies? And when you load the data, how do you know which data goes to which enemy?

Sorry if this is a stupid/misguided question, but I’m very new to saving and loading.

First of all: I invite you to take a look at my SerializeHelper aset, it’s free and is aimed at teaching the basics of datas serializing and saving/loading functionality for any game. You will spend a days just understanding it and reading up on topics on MSDN; there’s no way around it. Serialization in combination with Unity is a fairly advanced and complex topic with numerous pitfalls. No quick and easy works-for-all solution there :slight_smile:

The question you asked is answered by SerializeHelper. Basically, you have to go through all the GameObjects that need to have some of their data saved, and create a new instance of a container class for each which holds the data. This instance can then be added to a list or array and serialized.
You also have to find a way to identify each GameObject between saving and loading so the right data can be given back to the right GameObject. SerializeHelper does this by generating a unique ID via GUID.