- Home /
NullReferenceException: Object reference not set to an instance of an object
Have been trying to fix this error for hours now, and i'm at my wits end as to why this error is happening.
Here is the full error message;
NullReferenceException: Object reference not set to an instance of an object BaseCharacter.SetupVitalModifiers () (at Assets/Scripts/Character Classes/BaseCharacter.cs:105) BaseCharacter.SetupVitals () (at Assets/Scripts/Character Classes/BaseCharacter.cs:74) BaseCharacter.Awake () (at Assets/Scripts/Character Classes/BaseCharacter.cs:25)
CharacterGenerator.Start () (at Assets/Scripts/Character Classes/CharacterGenerator.cs:16)
I've been following along with a tutorial up on youtube (playlist here: https://www.youtube.com/playlist?annotation_id=annotation_801479&feature=iv&list=PLE5C2870574BF4B06&src_vid=wrsM7UOjLUw) and got up to EP 23 without any trouble, than this happened. I've scoured the internet for a solution, but nothing is working. Below are the two C# files the error mentions.
Base Character: http://pastebin.com/0sn6sKSe
Character Generator: http://pastebin.com/BX9qziKe
I've no idea what is actually going wrong and have gone back over the videos that cover the code in these files multiple times and just can't spot it. Placing down debug.log's didnt help too much.
Any help is greatly appreciated
It appears that _primaryAttribute in BaseCharacter.cs has the correct length, but the object it is returning is null. Did you not setup each item in the Attribute Array. We can assume it's not an index problem since it was able to retrieve the null object from the array from the int value of the AttributeName.Concentration enum.
You can also see that the array is being initialized with a capacity in the Awake function, but where are the objects of type Attribute co$$anonymous$$g from that should be added to the array?
It should be happening in method SetupPrimaryAttributes(); that happens right below the array capacity set. Something is dorked up.
You may want to poke around the videos some more in that play list, feels like you're missing something.
Answer by Cinntaxx · Jan 01, 2015 at 08:14 PM
You put me on the right track there @Landern.
But it wasnt to do with _primaryAttribute or the attribute class.
It ended up being a problem in the AdjustBaseValue method in an entirely different class that isnt mentioned in the error log. Some debugging made me notice things weren't returning a second time during the calculation in the method. Something to the effect of the calculations not passing the float ratio only once before tripping up on itself.
Thanks for the help! :)
Your answer
