Instanciating multiple objects with the same base characteristics

In regular programming, I would make something like a “Person” class, containing variables like “name”, “race”, “age”, “Job”, “health”, “money”, “inventory”, etc… And then I would do something like:

Person p1 = new Person(bla,bla,bla); … or something like that.

But in Unity I need a physical “body” object to be carrying this information, and I need to be able to instance multiple people, with different names, ages, etc…

I’m basically thinking about messing around with AI and having a working city populated with people going around according to their needs, move along NavMeshes and responding to events.

How do you recommend I do the Instancing of the people? I’ve been looking at serializable objects, scriptable objects… But I’m having trouble figuring out what I should use and how…

Hi @snunes - I think you have are many options, and I’m pretty much beginner - but here are some ideas;

A. Create base class MonoBehaviour character, which has basic features like Gender (m/f) and mesh it uses. Then create sub classes. There could be for example city employee, then sub class fireman, then sub class for some boss type. Then Create prefabs for these. You could put these into lists by type, to avoid editor limitations with inspector related serialization of derived custom classes. Then pick your characters from these lists.

B. Put your data / values in ScriptableObjects. Person ScriptableObject might have name, occupation, mesh it uses. Then you have a generic character container prefab with MonoBehaviour attached. When game runs you’ll instantiate generic containers, your attached script picks maybe some random data ScriptableObject, puts it into containers slot, and calls it’s methods to create it’s mesh, whatever it happened to be.