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 yanebra · Apr 26, 2013 at 01:46 PM · nullreferenceexceptionplayerprefsnguiunlock

NullReferenceException!! Please Give a Hand

Hi, all Unity Hero, I have a question to execute the following script which is the unlock system by PlayerPrefs, NGUI is used as plugins, The Unity shows me the following

,"NullReferenceException unlock system1.Update () (at Assets/Scripts/unlock system1.js:19)"

and I have no any clue to solve it, please kindly give me a hand.

 #pragma strict
 
 var levelReached1 : int =0;
 var levelReached2 : int =0;
 var levelReached3 : int =0;
 
 
 levelReached1 = PlayerPrefs.GetInt("1");
 levelReached2 = PlayerPrefs.GetInt("2");
 levelReached3 = PlayerPrefs.GetInt("3");
 
 
 
 
 function Update(){
 
 var S1B : UIButton = GameObject.Find("S1 Button").GetComponent(UIButton);
 var S2B : UIButton = GameObject.Find("S2 Button").GetComponent(UIButton);
 var S3B : UIButton = GameObject.Find("S3 Button").GetComponent(UIButton);     <-- Here
 
 
 
 if(levelReached1 == 1)
 {S1B.active = true;
  S2B.active = true;}
 else if (levelReached1 ==0)
 {S1B.active = true;
  S2B.active = false;}
  
  if(levelReached2 == 2)
  {S2B.active = true;
  S3B.active = true;}
 else if (levelReached2 ==0)
 {S2B.active = true;
  S3B.active = false;}
  
  if(levelReached3 == 3)
  {}
 else if (levelReached3 ==0)
 {}
  
  
  }
  
Comment
Add comment · Show 4
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 robertbu · Apr 26, 2013 at 02:11 PM 0
Share

Insert around line 20:

 Debug.Log(S1B + " - " + S2B + " - " + S3B);

I'm guessing that one or more of these is not being found. Carefully check to make sure the name in the Find() and the game object name are an exact match.

avatar image yanebra · Apr 26, 2013 at 02:42 PM 0
Share

Re: Robertbu

Thx for your kindly help, I have added the Debug.Log on line20, However, the Null Reference Exception is still appear from Unity. I have checked all of the name are excatly the same with the Game Object, any hints for tackling this problem?

avatar image robertbu · Apr 26, 2013 at 02:48 PM 0
Share

@yanebra - I've converted your answer to a comment. The answer field is for actual answers. By using it for comments you indicate that your question has been answered and fewer people will view it.

So did the Debug() statement indicate that any of the three was null? The only way I can see that this code will produce the error you describe is if the Find() fails or if the game object does not contain a UIButton component. Note that even an extra space in the name or a different letter case will cause the Find() to fail.

avatar image yanebra · May 05, 2013 at 09:22 AM 0
Share

@robertbu $$anonymous$$any thx to you, I have fixed it, thx to guide me in a right way. Happy develope to you!

0 Replies

· Add your reply
  • Sort: 

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

12 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

Related Questions

Multiple Cars not working 1 Answer

NullReferenceException: Object reference not set to an instance of an object. 2 Answers

NGUI Action Bar Questions 0 Answers

PlayerPrefs HighScore problems, it doesn't work. 4 Answers

Help with NullReferenceException 1 Answer


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