Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by modernator24 · Apr 09, 2017 at 09:57 AM · scripting problemexceptionunassignedreferenceexcept

Variable has been assigned but has UnassignedReferenceExcecption

This is my script. You can see that declared some variables at top:

 var QuestAccepted = false;
 var TextBoxOnCheck: boolean = false;
 var MessageBox: GameObject;
 var TextBox: GameObject;
 var QuestBox: GameObject;
 var QuestText: GameObject;

 function OnMouseDown() {
     if(!TextBoxOnCheck) {
         MessageBox.SetActive(true);
 
         if(!QuestAccepted) {
             TextBox.GetComponent.<Text>().text = 'Villager: Hello, some bandit have stollen my money. Could you retrieve it from them on the other side of the river?\n[F] to Accept, [X] to refuse.';
         }
         else {
             TextBox.GetComponent.<Text>().text = 'Villager: Get going then!';
         }
     }
     else {
         MessageBox.SetActive(false);
     }
 
     TextBoxOnCheck = !TextBoxOnCheck;
 }
 
 function CloseMessageBox() {
     MessageBox.SetActive(false);
     TextBoxOnCheck = false;    
 }
 
 function AcceptQuest() {
     QuestText.GetComponent.<Text>().text = 'Active Quest: Recover the loot';
     QuestAccepted = true;
     TextBox.GetComponent.<Text>().text = 'Villager: Nice! I\'ll be waiting here, tell me when your job is done!';
 
     //yield WaitForSeconds(3);
     //CloseMessageBox();
 }
 
 function Update() {
     if(Input.GetButtonDown('Use')) {
         AcceptQuest();
     }
     else if(Input.GetButtonDown('Cancel')) {
         CloseMessageBox();
     }
 }

And those are assigned in inspector as I dragged and dropped. When the game starts, all functions works well but this error message is in the console:

 UnassignedReferenceException: The variable QuestText of Quest001 has not been assigned.
 You probably need to assign the QuestText variable of the Quest001 script in the inspector.
 UnityEngine.GameObject.GetComponent[Text] () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GameObjectBindings.gen.cs:38)
 Quest001.AcceptQuest () (at Assets/Scripts/Quest001.js:34)
 Quest001.Update () (at Assets/Scripts/Quest001.js:44)

I removed the script and re-attached but still won't worked. If it's actually didn't assigned, it should be not work but it is working. What am I missing?

Comment
Add comment · Show 3
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 modernator24 · Apr 10, 2017 at 04:20 AM 0
Share

@hexagonius Thanks!

avatar image modernator24 · Apr 16, 2017 at 11:06 AM 0
Share

@hexagonius Can you post your comment as answer? I want to finish this question.

avatar image AurimasBlazulionis modernator24 · Apr 16, 2017 at 11:37 AM 0
Share

I did it for him

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by hexagonius · Apr 09, 2017 at 11:00 PM

Search the hierarchy for the script name, it's probably a duplicate you're not paid attention to.

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 modernator24 · Apr 16, 2017 at 04:59 PM 0
Share

$$anonymous$$any thanks!

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

124 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

transform.find exception if child does not exist 1 Answer

It won't let me use it on my character, and says it needs to derive from MonoBehaviour,It won't let me put this script onto my character, it says it needs to derive from MonoBehaviour 1 Answer

C# Unity dot syntax exercise correct solution? 1 Answer

I want to do a pause panel 1 Answer

Set cursor position at the middle of the screen. 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