error please help

I got this error when i run this script

NullReferenceException: Object reference not set to an instance of an object
CharacterGenerator.DisplayName () (at Assets\Script\Player Classes\CharacterGenerator.cs:64)
CharacterGenerator.OnGUI () (at Assets\Script\Player Classes\CharacterGenerator.cs:50)
UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean)
UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean)
UnityEditor.GameView:OnGUI()
System.Reflection.MonoMethod:InternalInvoke(Object, Object[ ])
System.Reflection.MonoMethod:InternalInvoke(Object, Object[ ])
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[ ], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[ ])
UnityEditor.HostView:Invoke(String)
UnityEditor.DockArea:OnGUI()

what this meen all the gui don’t show up

and here is the code

using UnityEngine;
using System.Collections;
using System;			//Used for the Enum class.

public class CharacterGenerator : MonoBehaviour {
	private PlayerCharacter _toon;
	private const int STARTING_POINTS = 350;
	private const int MIN_STARTING_ATTRIBUTE_VALUE = 10;
	private const int STARTING_VALUE = 50;
	private int pointleft;
	
	private const int OFFSET = 5;
	private const int LINE_HEIGHT = 20;
	
	private const int STAT_LABEL_WIDTH = 100;
	private const int BASEVALUE_LABEL_WIDTH = 30;
	private const int BUTTON_WIDTH = 20;
	private const int BUTTON_HEIGHT = 20;
	
	private int statStattingPos = 40;
	
	public GUISkin mySkin;
	
	public GameObject playerPrefab;

	// Use this for initialization
	void Start () {
		GameObject pc = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity) as GameObject;
		pc.name = "Player";
		
//		_toon = new PlayerCharacter();
//		_toon.Awake();
		_toon = pc.GetComponent<PlayerCharacter>();
		
		pointleft = STARTING_POINTS;
		
		for (int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
			_toon.GetPrimaryAttribute(cnt).BaseValue = STARTING_VALUE;
			pointleft -=(STARTING_VALUE - MIN_STARTING_ATTRIBUTE_VALUE);
		}
		_toon.StatUpdate();
	}
	
	// Update is called once per frame
	void Update () {
	}
	
	void OnGUI () {
		GUI.skin = mySkin;
		DisplayName();
		DisplayPointleft();
		DisplayAttributes();
		DisplayVitals();
		DisplaySkills();
		
		if (_toon.Name == "" || pointleft > 0)
			DisplayCreateLabel();
		else
			DisplayCreateButton();
	}
	
	private void DisplayName() {
		GUI.Label(new Rect(10, 10, 50, 25), "Name");
		_toon.Name = GUI.TextField(new Rect(65, 10, 100, 20), _toon.Name);
	}
	
	private void DisplayAttributes() {
		 for (int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
			 GUI.Label(new Rect( OFFSET,												//x
										  statStattingPos + (cnt * LINE_HEIGHT),	//y
										  STAT_LABEL_WIDTH,								//width
										  LINE_HEIGHT											//height
						  ), ((AttributeName)cnt).ToString());
			 
			 GUI.Label(new Rect( STAT_LABEL_WIDTH + OFFSET,				//x
							              statStattingPos + (cnt * LINE_HEIGHT),	//y
										  BASEVALUE_LABEL_WIDTH,						//width
										  LINE_HEIGHT											//height
						  ), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
			 
			 if (GUI.Button(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH, //x
												 statStattingPos + (cnt * BUTTON_HEIGHT),						//y
												 BUTTON_WIDTH,																//width
												 BUTTON_HEIGHT																//height
						  ), "-")) {
				 if (_toon.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE) {
					 _toon.GetPrimaryAttribute(cnt).BaseValue--;
					 pointleft++;
					 _toon.StatUpdate();
				 }
			 }
			 if (GUI.Button(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH + BUTTON_WIDTH,	//x
												 statStattingPos + (cnt * BUTTON_HEIGHT),													//y	
												 BUTTON_WIDTH, 																						//width
												 BUTTON_HEIGHT																							//height
						  ), "+")) {
				 
					 if (pointleft > 0) {
					 _toon.GetPrimaryAttribute(cnt).BaseValue++;
					 pointleft--;
					 _toon.StatUpdate();
				 }
			 }
	     }
   }
   
   private void DisplayVitals () {
	     for (int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
			  GUI.Label(new Rect( OFFSET, 														//x
										   statStattingPos + ((cnt + 7) * LINE_HEIGHT),		//y
										   STAT_LABEL_WIDTH, 										//width
										   LINE_HEIGHT													//height
						  ), ((VitalName)cnt).ToString());											
			  
			 GUI.Label(new Rect( OFFSET + STAT_LABEL_WIDTH,							//x
										  statStattingPos + ((cnt + 7) * LINE_HEIGHT),		//y
										  BASEVALUE_LABEL_WIDTH, 									//width
										  LINE_HEIGHT														//height
						  ), _toon.GetVital(cnt).AdjustedBaseValue.ToString());
		 } 
   }
   
   private void DisplaySkills () {
	     for (int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
			  GUI.Label(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH + BUTTON_WIDTH * 2 + OFFSET * 2,	//x
										   statStattingPos + (cnt * LINE_HEIGHT),																					//y
										   STAT_LABEL_WIDTH,																												//width
										   LINE_HEIGHT																														//height
						  ), ((SkillName)cnt).ToString());
			  
			 GUI.Label(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH + BUTTON_WIDTH * 2 + OFFSET * 2 + STAT_LABEL_WIDTH,	//x
										  statStattingPos + (cnt * LINE_HEIGHT),																												//y
										  BASEVALUE_LABEL_WIDTH,																																	//width
										  LINE_HEIGHT																																						//height
						  ), _toon.GetSkill(cnt).AdjustedBaseValue.ToString());
		 } 
    }
	
	private void DisplayPointleft () {
		GUI.Label(new Rect(250, 10, 100, 25), "Points Left: " + pointleft.ToString());
	}
	private void DisplayCreateLabel() {
		GUI.Label(new Rect( Screen.width / 2 - 50, statStattingPos + (10 * LINE_HEIGHT), 100, LINE_HEIGHT), "Creating....", "Button");
	}
	
	private void DisplayCreateButton() {
		if(GUI.Button(new Rect( Screen.width / 2 - 50, statStattingPos + (10 * LINE_HEIGHT), 100, LINE_HEIGHT), "Create")) {
				 GameSettings gsScript = GameObject.Find("__GameSettings").GetComponent<GameSettings>();
				 
				 UpdateCurVitalValues();
			
			     gsScript.SaveCharacterData();
			
				 Application.LoadLevel("Level1");
		 }
	}
	
	private void UpdateCurVitalValues () {
			 for (int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
				 _toon.GetVital(cnt).CurValue = _toon.GetVital(cnt).AdjustedBaseValue;
		 }
	}
}

Can you double-check that you attached your “PlayerCharacter” script to your “playerPrefab”?

it means that you have a variable that doesn’t have a value. lets say that you created an empty variable named “dog” and intended to plug in a dog model in your inspector (or in code). you then intended to access that variable to read it’s data.

however, lets say that you forgot to plug in the actually dog content, what ever it was. Unity will return this error message. the word “reference” in this case describes your variable – a sort of a ‘pointer’ in code that points at some data. the data, however, doesn’t exist – no data has been instanced (copied from template and loaded into memory).

so your object reference (dog variable) isn’t set to an instance of an object ( content for that variable)

I have attached my “PlayerCharacter” script to the “playerPrefab”

I got it to work i have forgot to add the playerCharacter Script to the player

Called it! Glad you got it working. :smile:

thanks