Null Reference Exception Error. Modified Stats. Need Help.

All right, having trouble with null reference exceptions…again. So I decided to make an account on Unity in hopes that one of your gifted scripters can help an apprentice such as myself. Here is the error:

NullReferenceException: Object reference not set to an instance of an object
ModifiedStats.CalculateModValue () (at Assets/Scripts/Character Classes/ModifiedStats.cs:19)
ModifiedStats.Update () (at Assets/Scripts/Character Classes/ModifiedStats.cs:29)
BaseCharacterClass.StatsUpdate () (at Assets/Scripts/Character Classes/BaseCharacterClass.cs:193)
CharacterGenerator.Start () (at Assets/Scripts/Character Classes/CharacterGenerator.cs:26)

Some scripts to aid your assistance:

using System.Collections.Generic;
public class ModifiedStats : BaseStats {
	private List<ModifyingAttribute> _mods; //List of Attributes that Modify Stat
	private int _modValue; //amount added to baseValue of modifiers
	
	public ModifiedStats() {
		_mods = new List<ModifyingAttribute>();
		_modValue = 0;
	}
	
	public void AddModifier( ModifyingAttribute mod) {
		_mods.Add(mod);
	}
	
	private void CalculateModValue() {
		
		if(_mods.Count > 0 )
			foreach (ModifyingAttribute att in _mods) 
				_modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);  
		
		
	}
	
	public new int AdjustedBaseValue {
		get{ return _baseValue + _buffValue + _modValue; }
	}
	
	public void Update() {
		CalculateModValue();
	}
}

public struct ModifyingAttribute {
	public Attribute attribute; 
	public float ratio; 
	
}

Another one:

using UnityEngine;
using System.Collections;
using System;

public class BaseCharacterClass : MonoBehaviour {
	private string _name;
	private int _level;
	private uint _freeEXP;
	
	private Attribute[] _primaryAttribute;
	private Vital[] _vital;
	private Skill[] _skill; 
	
    public void Awake() {
		_name = string.Empty;
		_level = 0;
		_freeEXP = 0;
		

		
		_primaryAttribute = new Attribute[Enum.GetValues(typeof(AttributeName)).Length];
		_vital = new Vital[Enum.GetValues(typeof(VitalName)).Length];
		_skill = new Skill[Enum.GetValues(typeof(SkillName)).Length]; 
		
		SetupVitals();
		SetupPrimaryAttribute();
		SetupSkills();
		
		
		
		
		
	}

	
	public string Name {
		get{return _name; }
		set{ _name = value; }
	}
	public int Level {
		get{return _level;}
		set{_level = value;}
	}
	public uint FreeEXP {
		get{return _freeEXP;}
		set{_freeEXP = value;}
	}
	public void AddEXP(uint exp) {
		_freeEXP += exp;
		
	CaluclateLevel();
		
	}
	// add more to this one, incomplete
	//take average of all players skills and assign that as the player level
		
	public void CaluclateLevel() {
	}
	
	public void SetupPrimaryAttribute() {
		for(int cnt = 0; cnt < _primaryAttribute.Length; cnt ++)
			_primaryAttribute[cnt] = new Attribute();
		
	}
	
	public void SetupVitals() {
				for(int cnt = 0; cnt < _vital.Length; cnt ++)
			_vital[cnt] = new Vital();
		
		SetUpVitalModifiers();


		
		
	}
	
	public void SetupSkills() {
			for(int cnt = 0; cnt < _skill.Length; cnt ++) 
			_skill[cnt] = new Skill();
		
		SetUpSkillModifiers();
		

		
		
	}
	public Attribute GetPrimaryAttribute(int index) {
		return _primaryAttribute[index]; 
	}
	
	public Vital GetVital(int index) {
		return _vital[index];
	}
	public Skill GetSkills(int index) {
		return _skill[index];
	}
	private void SetUpVitalModifiers(){
		//health
		GetVital((int)VitalName.Vitality).AddModifier(new ModifyingAttribute{attribute = GetPrimaryAttribute((int)AttributeName.Physique), ratio = .5f});
		
		//energy
		ModifyingAttribute energyModifier = new ModifyingAttribute();
		energyModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
		energyModifier.ratio = 1; 
		
		GetVital ((int)VitalName.Energy).AddModifier(energyModifier);
		
		
		
	}
	private void SetUpSkillModifiers(){
		//physique
		ModifyingAttribute SwordsmanshipModifier = new ModifyingAttribute();
		ModifyingAttribute AxemanshipModifier = new ModifyingAttribute();
		ModifyingAttribute BlockModifier = new ModifyingAttribute();
		
		SwordsmanshipModifier.attribute = GetPrimaryAttribute((int)AttributeName.Physique);
		SwordsmanshipModifier.ratio = .33f;
		
		AxemanshipModifier.attribute = GetPrimaryAttribute((int)AttributeName.Physique);
		AxemanshipModifier.ratio = .33f;
		
		BlockModifier.attribute = GetPrimaryAttribute((int)AttributeName.Physique);
		BlockModifier.ratio = .33f;

		GetSkills ((int)SkillName.Swordsmanship).AddModifier(SwordsmanshipModifier);
		GetSkills ((int)SkillName.Axemanship).AddModifier(AxemanshipModifier);
		GetSkills ((int)SkillName.Block).AddModifier(BlockModifier);
		
		//finesse
		ModifyingAttribute DaggeryModifier = new ModifyingAttribute();
		ModifyingAttribute MarksmanshipModifier = new ModifyingAttribute();
		ModifyingAttribute TacticsModifier = new ModifyingAttribute();
		
		DaggeryModifier.attribute = GetPrimaryAttribute((int)AttributeName.Finesse);
		DaggeryModifier.ratio = .33f;
		
		MarksmanshipModifier.attribute = GetPrimaryAttribute((int)AttributeName.Finesse);
		MarksmanshipModifier.ratio = .33f;
		
		TacticsModifier.attribute = GetPrimaryAttribute((int)AttributeName.Finesse);
		TacticsModifier.ratio = .33f;
		
		GetSkills ((int)SkillName.Daggery).AddModifier(DaggeryModifier);
		GetSkills ((int)SkillName.Marksmanship).AddModifier(MarksmanshipModifier);
		GetSkills ((int)SkillName.Tactics).AddModifier(TacticsModifier);
		
		//lordcraft
		ModifyingAttribute ChaosModifier = new ModifyingAttribute();
		ModifyingAttribute LightModifier = new ModifyingAttribute();
		
		ChaosModifier.attribute = GetPrimaryAttribute((int)AttributeName.Lordcraft);
		ChaosModifier.ratio = .33f;
		
		LightModifier.attribute = GetPrimaryAttribute ((int)AttributeName.Lordcraft);
		LightModifier.ratio = .33f;
		
		GetSkills ((int)SkillName.Light_Prayers).AddModifier(LightModifier);
		GetSkills ((int)SkillName.Chaos_Prayers).AddModifier(ChaosModifier);
		
		//charisma
		
		ModifyingAttribute CoercionModifier = new ModifyingAttribute();
		ModifyingAttribute MercantileModifier = new ModifyingAttribute();
		
		CoercionModifier.attribute = GetPrimaryAttribute((int)AttributeName.Charisma);
		CoercionModifier.ratio = .33f;
		
		MercantileModifier.attribute = GetPrimaryAttribute((int)AttributeName.Charisma);
		MercantileModifier.ratio = .33f;
		
		GetSkills ((int)SkillName.Coercion).AddModifier(CoercionModifier);
		GetSkills ((int)SkillName.Mercantile).AddModifier(MercantileModifier);
		
		//willpower
		ModifyingAttribute NaturalModifier = new ModifyingAttribute();
		ModifyingAttribute DominateModifier = new ModifyingAttribute();
		
		NaturalModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
		NaturalModifier.ratio = .33f;
		
		DominateModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
		DominateModifier.ratio = .33f;
		
		GetSkills ((int)SkillName.Natural_Arts).AddModifier(NaturalModifier);
		GetSkills ((int)SkillName.Domination_Arts).AddModifier(DominateModifier);
		
	
	}
	
	public void StatsUpdate() {
		for(int cnt = 0; cnt < _vital.Length; cnt ++)
			_vital[cnt].Update();
		for(int cnt = 0; cnt < _skill.Length; cnt ++)
			_skill[cnt].Update();
	}
}

Thank you for all of your help. I am very appreciative.

I’ve got a feeling you need to initialise the values in your struct to some defaults like so:

public struct ModifyingAttribute 
{
    public Attribute attribute; 
    public float ratio; 

    // See if this works
    ModifyingAttribute(Attribute att = new Attribute(), float r = 0.0f)
    {
        attribute = att;
        ratio = r;
    }  
}

I know this works in C++, not sure if it works in C#