Intro
So I’ve been debugging this through, thus to no avail. I tried to make sense of it thus no luck. I know what the problem is (I think) but I cannot find out why it do as it do
What seems to be the problem
So what I think is the problem is simply that it cannot access to _skill variable.
I do not know why it do this. The “SkillName” is a list of enums which is my skills.
Which I seem to be able to get and also I can in the start of the code return the length but not under the funcion of “SetupSkill”
The code itself where I think the error is in
using UnityEngine;
using System.Collections;
using System;
public class BaseChar : 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];
SetupPrimaryAtt();
SetupVital();
SetupSkills();
}
// Use this for initialization
#region All skill stuff
#region Set and get
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;}
}
#endregion
#endregion
public void AddExp(uint exp){
_freeExp += exp;
CalcLvl();
}
public void CalcLvl(){
//Level things :smile:D
}
private void SetupPrimaryAtt(){
for(int cnt =0; cnt < _primaryAttribute.Length; cnt++){
_primaryAttribute[cnt] = new Attribute();
}
}
private void SetupVital(){
for(int cnt =0; cnt < _vital.Length; cnt++){
_vital[cnt] = new Vital();
//SetupVitalMod();
}
}
private void SetupSkills(){
for(int cnt =0; cnt < _skill.Length; cnt++){
_skill[cnt] = new Skill();
SetupSkillMod();
}
}
public Attribute GetPrimaryAttribute(int index){
return _primaryAttribute[index];
}
public Vital GetVital(int index){
return _vital[index];
}
public Skill GetSkill(int index){
return _skill[index];
}
private void SetupVitalMod(){
//hp
ModifyAtt health = new ModifyAtt();
health.attribute = GetPrimaryAttribute((int)AttributeName.Endurance);
health.ratio = .5f;
GetVital((int)VitalName.Health).AddMod(health);
//stam
ModifyAtt stam = new ModifyAtt();
stam.attribute = GetPrimaryAttribute((int)AttributeName.Endurance);
stam.ratio = 2.7f;
GetVital((int)VitalName.Energy).AddMod(stam);
//mp
ModifyAtt mp = new ModifyAtt();
mp.attribute = GetPrimaryAttribute((int)AttributeName.Int);
mp.ratio = 2.7f;
GetVital((int)VitalName.Mana).AddMod(mp);
}
private void SetupSkillMod(){
ModifyAtt WepMastery = new ModifyAtt();
ModifyAtt Def = new ModifyAtt();
ModifyAtt Magic = new ModifyAtt();
ModifyAtt Archery = new ModifyAtt();
WepMastery.attribute = GetPrimaryAttribute((int)AttributeName.Str);
Def.attribute = GetPrimaryAttribute((int)AttributeName.Endurance);
Magic.attribute = GetPrimaryAttribute((int)AttributeName.Int);
Archery.attribute = GetPrimaryAttribute((int)AttributeName.Dex);
GetSkill((int)SkillName.Weapon_Mastery).AddMod(WepMastery);
GetSkill((int)SkillName.Defence).AddMod(Def);
GetSkill((int)SkillName.Magic).AddMod(Magic);
GetSkill((int)SkillName.Archery).AddMod(Archery);
}
public void StatUpdate(){
for(int cnt =0; cnt < _vital.Length; cnt++){_vital[cnt].Update();}
for(int cnt =0; cnt < _skill.Length; cnt++){_skill[cnt].Update();}
}
}
The error message
NullReferenceException: Object reference not set to an instance of an object
CharacterGenerator.DisplaySkill () (at Assets/Script/Script/Player/CharacterGenerator.cs:84)
CharacterGenerator.OnGUI () (at Assets/Script/Script/Player/CharacterGenerator.cs:41)