Errors, Errors Everywhere

Hi Im new to the forum and kinda new to unity I’ve been doing it for about a month but scripting i’ve just begun.
I’m familiar with the basics and I can understand tutorials well but I’m just wondering what does this script error mean?

NullReferenceException: Object reference not set to an instance of an object
CharacterGenerator.DisplayVitals () (at Assets/Scripts/Character Classes/CharacterGenerator.cs:42)
CharacterGenerator.OnGUI () (at Assets/Scripts/Character Classes/CharacterGenerator.cs:23)

I need help please and thank you.:smile:

It means you’re trying to reference something that doesn’t exist.

–Eric

Is there anyway I can fix it heres my script

That usually happens when you try to access an object before it is properly initialized.

You can add one element at a time to your DisplayVital() function to narrow down which object access failed. For example, you can start with the …For… loop first by removing everything inside leaving an empty for loop to see if an error will be thrown, then add one element at a time till the error hits.

Well I cut out that last line of script in my DisplayVitals() function and it seemed to take away that error i just got a warning
It seems that was causing the problem but i need that line to get the actual value of my Character so basically the numbers that were
supposed to be beside it

Im making a skill and stat Increase page

The main idea is usually :

  • Reference to an object is required to make the code line work.
  • Is there currently a reference ?

Since there is an error message, the answer should be no, so :

  • Why isn’t there yet a reference ? Shouldn’t I have already made it ?

I would advise you to have maybe a look at GetVitals function.

By the way :

_toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.[COLOR="red"]T oString())[/COLOR];