• 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 Story Specialist · Sep 20, 2011 at 10:34 AM · javascriptbugunassigned

Unassigned bug?

Riddle me this, my friends...

When running this script:

 var materialArray : Material[];
 var thisObject : GameObject;
 private var index : int = 0;
 
 function Awake () {
     thisObject.renderer.material = materialArray[index];
 }
 
 function Update () {
 
     if (Input.GetKeyUp("1")) {
         index--;
         if (index < 0) {
             index = materialArray.Length - 1;
         }
         thisObject.renderer.material = materialArray[index];
     }
     
     if (Input.GetKeyUp("2")) {
         index++;
         if (index > materialArray.Length - 1) {
             index = 0;
         }
         thisObject.renderer.material = materialArray[index];
     }
     
 }
 
 function OnMouseOver () {
     GlobalVariables.DebugMessage = "Looking at me!";
     Debug.Log ("OnMouseOver");
 }
 
 function OnMouseExit () {
     GlobalVariables.DebugMessage = " Not looking at me!";
     Debug.Log ("OnMouseExit");
 }

I get the following error:

     UnassignedReferenceException: The variable thisObject of 'CheckIfFocus' has not been assigned.
 You probably need to assign the thisObject variable of the CheckIfFocus script in the inspector.
 CheckIfFocus.Awake () (at Assets/Scripts/CheckIfFocus.js:7)

Now here's the funny part: that GameObject has in fact been assigned (it's the object the script is on), and what's more...the script works! It does everything it is supposed to do (apart from the MouseOver/Exit), but still I get the error saying it doesn't work. Is this a bug or am I completely overlooking something?

alt text

I've tried renaming the variable, making a new one, I've even tried exporting to a Unity package and importing in a new Project, as someone suggested. Nothing works.

Can anyone help me out with this mystery?

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
2
Best Answer

Answer by CHPedersen · Sep 20, 2011 at 10:39 AM

A post in the forums reports that this occurs when the same script is assigned to two different objects. See the thread I linked to. This is just a guess, but do you perhaps have the same problem?

Comment
Add comment · Show 2 · 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 CHPedersen · Sep 20, 2011 at 10:40 AM 0
Share

This other question:

http://answers.unity3d.com/questions/39524/getting-unassignedreferenceexception-even-though-r.html

Also seems to have the same problem, supporting the theory.

avatar image Story Specialist · Sep 20, 2011 at 01:13 PM 0
Share

Oh, jeez, that seems to be the case. $$anonymous$$an, no idea how that happened, but there you go, problem solved. Thank you! Sometimes you just blind yourself, staring at your code, only to overlook the simplest of explanations.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Gravity Switch by button? 1 Answer

Variable value not changing when using OnTriggerStay() 0 Answers

Why isn't this public variable working? (JS) 1 Answer

Why isn't my word generator working? 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