javascript NullReferenceException: Object reference not set to an instance of an object
Hi everyone. Well, i'm trying to make an Armor system for my RPG like game. But i'm having trouble setting the starter armor value to the character when it is first instantiated. First, i have a script with a class called Armor. Like this:
ArmorScript.js
#pragma strict
import System.Collections.Generic;
class Armor{
var listValuesBonus: List.<float>;
}
The listValuesBonus will receive the values of defense, number of slots (0 to 2), and the bonuses of these slots. Also, in the character script i have this:
CharacterScript.js
#pragma strict
import System.Collections.Generic;
var classe: PersonagemCombatenteClasse;
var status : PersonagemCombatenteStatus;
var armor : List.<Armor>;
var armorInitial: Armor;
function Awake() {
classe = StatusPersonagens.GetClasseCombatente();
status = StatusPersonagens.GetCombatenteStatusBasico(classe);
armor = new List.<Armor>();
armorInitial = new Armor();
if (armorInitial == null){ //Tried this to figure out if armorInitial was null
Debug.Log("armorInitial == null"); //but it's not
} else if (armorInitial.listValuesBonus == null){
Debug.Log("listValuesBonus == null");
armorInitial.listValuesBonus.Add(1);
armorInitial.listValuesBonus.Add(0);
SetListArmorBonus(armorInitial);
}
}
function SetListArmorBonus (newArmor: Armor){
armor.Add(newArmor);
}
But when the character is instantiated and try to Add() the values to listValuesBonus i receive this message error:
NullReferenceException: Object reference not set to an instance of an object Combatente.Awake () (at Assets/Scripts/Combatente.js:22)
Can someone help, please? Thank for the attention and sorry for any english errors.
Your answer
![](https://koobas.hobune.stream/wayback/20220612083758im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
JS NullReferenceException: Object reference not set to an instance of an object 1 Answer
NullReferenceException: Object reference not set to an instance of an object 0 Answers
How do i fix this nullreferenceException 1 Answer
Help with JS script 0 Answers
NullReferenceException: Object reference not set to an instance of an object 3 Answers