- Home /
CAN SOMEONE FINALLY HELP ME!
I have asked A LOT of people, but no one can seem to help. I am sooo stuck it hurts my head, so please help me here. I need to fix my object reference not set to an instance of an object code... Here is one code( the (>) is where the problem shows):
private void SetupSkillModifiers() {
//Melee Offence
ModifyingAttribute MeleeOffenceModifier1 = new ModifyingAttribute();
ModifyingAttribute MeleeOffenceModifier2 = new ModifyingAttribute();
MeleeOffenceModifier1.attribute = GetPrimaryAttribute((int)AttributeName.Might);
MeleeOffenceModifier1.ratio = .33f;
MeleeOffenceModifier2.attribute = GetPrimaryAttribute((int)AttributeName.Nimbleness);
MeleeOffenceModifier2.ratio = .33f;
(>)GetSkill((int)SkillName.Melee_Offence).AddModifier(MeleeOffenceModifier1);
GetSkill((int)SkillName.Melee_Offence).AddModifier(MeleeOffenceModifier2);
as well as this section:
private void DisplaySkills() {
for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
GUI.Label(new Rect(250, 40 + (cnt * 25), 100, 25), ((SkillName)cnt).ToString());
GUI.Label(new Rect(355, 40 + (cnt * 25), 30, 25), _toon.GetSkill(cnt).AdjustedBaseValue.ToString());
}
I think this code might be the source of the problem I am having:
using UnityEngine;
using System.Collections;
using System; //added to access Enum Class
public class BaseCharacter : 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];
And Finally I added this code, which holds the SkillName variable. I believe it has some part in the problem. So heres the code:
public class Skill : ModifiedStat {
private bool _known;
public Skill() {
_known = false;
ExpToLevel = 25;
LevelModifier = 1.15f;
}
public bool Known {
get{ return _known; }
set{ _known = value; }
}
}
public enum SkillName {
Melee_Offence,
Melee_Defence,
Ranged_Offence,
Ranged_Defence,
Magic_Offence,
Magic_Defence
}
I hope all of these codes will help you guys help me... So if you don't think this is enough I have other codes that might help. ;)
Answer by Democre · Nov 20, 2012 at 12:35 AM
You are never calling SetupPrimarySkills before calling SetupSkillModifiers. Therefore your _skills array is still an array of null objects. Therefore when you call GetSkill it returns null.
Answer by Loius · Nov 17, 2012 at 07:31 PM
Your GetSkill function is returning null.
$$anonymous$$ake your GetSkill function return a value which is not null.
(hint: Since GetSkill isn't in the code here, that's as helpful as anyone can be)
Ok so I will find it... Check back in oh 15-20 $$anonymous$$ and I should have it
Alrite well I have no variable for GetSkill... I just have a variable for Skill...
Can you help me write something to fix my problem? All the skills are listed in one of my scripts above, but can you make it so i'm able to add more Skills and not have to change the code? I would highly appreciate this thanks!
Answer by kbeaud · Nov 18, 2012 at 01:30 AM
here is the GetSkill:
public Skill GetSkill(int index) {
return _skill[index];
}
Your answer
Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Error in script 1 Answer
Object Reference Error On Camera Script 1 Answer
Whats wrong with this simple code? 2 Answers
How do I fix this error in my code 2 Answers