An (In Depth) Introduction to Better NPCs
Posted 2 days ago
This is another feature that never made it into the final project but is worth noting. A really big thing that makes NPCs immersive is when they are essentially just a randomized clone. I spent a few days working on a script that would house relatively lightweight information on a Battalion. I indented for this project to be more freeform/fun to play with and I wanted there to be a tracking on how much damage you did to different groups/if they need to send in a new battalion

While I haven't played many open world games I can really apricate the persistence of important and semi-important NPCs.

I created a SoldierData structure that maintains whether or not a soldier is spawned, alive, the visual data, and some function data as well. The idea is that either a soldier prefab can either be spawned around these values or an already spawned soldier prefab that isn't bound to an identity could be then bound to a similar/identical preexisting identity.
public struct SoldierData
{
	public Rank rank;
	public HumanData.Ethnicity ethnicity;
	public HumanData.Name name;
	public HumanData.Gender gender;
	public bool isAlive = true;
	public bool spawned { get { return soldierInstance.IsValid(); } }
	//private bool isSpawned = false;
	public AiSoldier soldierInstance { get { return _soldierInstance; } set { _soldierInstance = value; } }
	private AiSoldier _soldierInstance;
	public SoldierData( HumanData.Name name, Rank rank, HumanData.Gender gender, HumanData.Ethnicity ethnicity, AiSoldier soldierInstance = null )
	{
		this.name = name;
		this.rank = rank;
		this.gender = gender;
		this.ethnicity = ethnicity;

		if ( soldierInstance != null )
		{
			this._soldierInstance = soldierInstance;
			//isSpawned = true;
		}
	}
}