• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

I keep getting the error "NullReferenceException: Object reference not set to an instance of an object RobotFollow.Update () (at Assets/Scripts/RobotFollow.js:23)" 1 Answer

Post-Processing Scripting ? 1 Answer

build with IL2CPP error unity 4.6.9 while making iOS build 1 Answer

Is there a way to prevent this weird project and solution generation done by Unity when using asmdef files? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges