Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by chrismcrae5712 · Sep 14, 2014 at 07:40 PM · error

Reference error -_- Annoyed please help

Okay so I am following a tutorial and yet again in the tutorial the guy jumped past the part where he fixed an error and now i am stuck trying to solve it. I am stuck and can't seem to figure out the next step on how to fix this error. (scripting is not my favorite) Any help is appreciated thanks. Here the errors:

NullReferenceException: Object reference not set to an instance of an object GameSettings.SaveCharacterData () (at Assets/Game Data/Player Data/Scripts/Character Stats/GameSettings.cs:24) CharacterGenerator.DisplayCreateButton () (at Assets/Game Data/Player Data/Scripts/Character Stats/CharacterGenerator.cs:116) CharacterGenerator.OnGUI () (at Assets/Game Data/Player Data/Scripts/Character Stats/CharacterGenerator.cs:52)

Heres my Codes.

CHARACTERGENERATOR

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class CharacterGenerator : MonoBehaviour 
 {
 
     private PlayerCharacter _player;
     private const int Talent_Points = 25;
     private const int Minimum_Starting_Attribute_Value = 15;
     private const int Starting_Value = 25;
     private int pointsLeft;
 
     public Texture2D cgTexture;
     public GUIStyle nbStyle;
     public GUIStyle pbStyle;
     public GUIStyle bgStyle;
     public GUIStyle tbStyle;
 
     public GUISkin gameSkin;
 
     public GameObject playerPrefab;
 
     void Start()
     {
         GameObject pc = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity) as GameObject;
         pc.name = "Character";
         _player = pc.GetComponent<PlayerCharacter>();
         _player.Awake();
         pointsLeft = Talent_Points;
         for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
             {
                 _player.GetPrimaryAttributes(cnt).BaseValue = Minimum_Starting_Attribute_Value;
             }
         _player.StatUpdate();
     }
 
     void Update()
     {
         //_player.StatUpdate();
     }
 
 
     void OnGUI()
     {
         GUI.skin = gameSkin;
         DisplayName();
         DisplayPointsLeft();
         DisplayAttributes();
         DisplayVitals();
         DisplaySkills();
         DisplayCreateButton();
     }
     private void DisplayName()
     {
         GUI.Label(new Rect(10, 10, 50, 25), "Name:");
         _player.Name = GUI.TextField(new Rect(65, 10, 250, 50), _player.Name, 14);
     }
 
     private void DisplayAttributes()
     {
         for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
         {
             GUI.Label (new Rect(10, 75 +(cnt * 30), 100, 25), ((AttributeName)cnt).ToString() );
             GUI.Label (new Rect(115, 75 +(cnt * 30), 30, 25), _player.GetPrimaryAttributes(cnt).AdjustedBaseValue.ToString() );
             if(GUI.Button(new Rect(165, 75 + (cnt * 30), 25, 25), " ", nbStyle))
             {
                 if(_player.GetPrimaryAttributes(cnt).BaseValue > Minimum_Starting_Attribute_Value)
                 {
                     _player.GetPrimaryAttributes(cnt).BaseValue--;
                     pointsLeft ++;
                     _player.StatUpdate();
                 }
             }
             if(GUI.Button(new Rect(195, 75 + (cnt * 30), 25, 25), " ", pbStyle))
             {
                 if(pointsLeft > 0)
                 {
                     _player.GetPrimaryAttributes(cnt).BaseValue++;
                     pointsLeft --;
                     _player.StatUpdate();
                 }
             }
         }
     }
 
     private void DisplayVitals()
     {
         for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++)
         {
             GUI.Label (new Rect(225, 75 +(cnt * 40), 100, 25), ((VitalName)cnt).ToString() );
             GUI.Label (new Rect(340, 75 +(cnt * 40), 30, 25), _player.GetVitals (cnt).AdjustedBaseValue.ToString() );
         }
     }
 
     private void DisplaySkills()
     {
         for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++)
         {
             GUI.Label (new Rect(415, 75 +(cnt * 40), 100, 25), ((SkillName)cnt).ToString() );
             GUI.Label (new Rect(530, 75 +(cnt * 40), 30, 25), _player.GetSkills (cnt).AdjustedBaseValue.ToString() );
         }
     }
 
     private void DisplayPointsLeft()
     {
         GUI.Label(new Rect(350, 10, 125, 25), "Points Left: " + pointsLeft.ToString());
     }
     private void DisplayCreateButton()
     {
         if(GUI.Button(new Rect(100, 500, 125, 35), "Create"))
         {
 
             GameSettings gsScript = GameObject.Find ("GameSettings").GetComponent<GameSettings>();
 
             gsScript.SaveCharacterData();
 
             Application.LoadLevel("DireQuest Game");
         }
     }
 }

GAMESETTINGS

 using UnityEngine;
 using System.Collections;
 
 public class GameSettings : MonoBehaviour {
 
     // Use this for initialization
     void Awake()
     {
         DontDestroyOnLoad(this);
     }
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     public void SaveCharacterData()
     {
         GameObject pc = GameObject.Find("pc");
 
         PlayerCharacter pcClass = pc.GetComponent<PlayerCharacter>();
 
         PlayerPrefs.SetString("PlayerName", pcClass.Name);
     }
 
     public void LoadCharacterData()
     {
 
     }
 }


Sorry for the length. Thanks again!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by VesuvianPrime · Sep 14, 2014 at 08:27 PM

GameObject.Find("pc"); is returning null

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Sep 14, 2014 at 10:45 PM 0
Share

Which means, in other words, that you don"'t have an object in your scene called "pc".

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Random exception error just showed up 0 Answers

Sync with visual studio 2010 error 1 Answer

,SUCCEDED(HR) Error 0 Answers

WeaponScript not working 0 Answers

Some problems after switch the game for iOS mode 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges