C# Problem (434395)

hi all,i need help.i got about 700 errors with this text
“NullReferenceException: Object reference not set to an instance of an object
CharacterGenerator.DisplayVitals () (at Assets/My Files/Scripts/Character Classes/CharacterGenerator.cs:41)
CharacterGenerator.OnGUI () (at Assets/My Files/Scripts/Character Classes/CharacterGenerator.cs:22)”

here is my code

	private void DisplayVitals() {
	for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
		GUI.Label(new Rect(10, 40 + ((cnt + 7) * 25), 100, 25), ((VitalName)cnt).ToString());
		GUI.Label(new Rect(115, 40 + ((cnt + 7) * 25), 30, 25), _toon.GetVital(cnt).AdjustedBaseValue.ToString());
		}
	}

and

	void OnGUI() {
		DisplayName();
		DisplayAttributes();
		DisplayVitals();
		DisplaySkills();
	}

thx in advance…

Can you double-check that “_toon” is not null?

i dont know where i should check it :S im bad with C#

Debug.Log("Is _toon null: " + (_toon == null));
GUI.Label(new Rect(115, 40 + ((cnt + 7) * 25), 30, 25), _toon.GetVital(cnt).AdjustedBaseValue.ToString());

If that logs out as “true”, then it means that you have not properly assigned an object to “_toon”.

when i add that to script i got
Is _toon null: True
UnityEngine.Debug:Log(Object)
CharacterGenerator: DisplayVitals() (at Assets/My Files/Scripts/Character Classes/CharacterGenerator.cs:41)
CharacterGenerator:OnGUI() (at Assets/My Files/Scripts/Character Classes/CharacterGenerator.cs:22)

That means that _toon, whatever it is supposed be, has no value. That would be why trying to call a function on it (_toon.GetVital()) generates an error.