Skip to main content
Distinguish the class and instances of that class
Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

How can I store a list of instances of different classes?

I am making a customizable save system for Unity. In my previous save systems, since they aren't designed to be modifiable, I already know what each save is going to contain. 

However, when making this new system, I want to create some kind of attribute like [Savable] that allows that class to be serialized into the save file. 

I figured the attribute would just store a list of classes, structs, etc, and then they would all be stored in some file. Aswell as, along with some other data. But how would I contain a list of class instances from these different classes?

I'm not talking about a list of instances of a specific classesclass like:

public List<MyClass>;

I need some way to store a list of different class instances. Or perhaps a way to store a list for each class instance idk. Something like this:

public List<SavableClasses>;

Is there any way I can do this?

How can I store a list of different classes?

I am making a customizable save system for Unity. In my previous save systems, since they aren't designed to be modifiable, I already know what each save is going to contain. However, when making this new system, I want to create some kind of attribute like [Savable] that allows that class to be serialized into the save file. I figured the attribute would just store a list of classes, structs, etc, and then they would all be stored in some file. Aswell as some other data. But how would I contain a list of classes?

I'm not talking about a list of specific classes like:

public List<MyClass>;

I need some way to store a list of different class instances. Or perhaps a way to store a list for each class instance idk. Something like this:

public List<SavableClasses>;

Is there any way I can do this?

How can I store a list of instances of different classes?

I am making a customizable save system for Unity. In my previous save systems, since they aren't designed to be modifiable, I already know what each save is going to contain. 

However, when making this new system, I want to create some kind of attribute like [Savable] that allows that class to be serialized into the save file. 

I figured the attribute would just store a list of classes, structs, etc, and then they would all be stored in some file, along with some other data. But how would I contain a list of class instances from these different classes?

I'm not talking about a list of instances of a specific class like:

public List<MyClass>;

I need some way to store a list of different class instances. Or perhaps a way to store a list for each class instance. Something like this:

public List<SavableClasses>;

Is there any way I can do this?

Source Link
Pow
  • 414
  • 1
  • 12

How can I store a list of different classes?

I am making a customizable save system for Unity. In my previous save systems, since they aren't designed to be modifiable, I already know what each save is going to contain. However, when making this new system, I want to create some kind of attribute like [Savable] that allows that class to be serialized into the save file. I figured the attribute would just store a list of classes, structs, etc, and then they would all be stored in some file. Aswell as some other data. But how would I contain a list of classes?

I'm not talking about a list of specific classes like:

public List<MyClass>;

I need some way to store a list of different class instances. Or perhaps a way to store a list for each class instance idk. Something like this:

public List<SavableClasses>;

Is there any way I can do this?