- Home /
Cannot assign GameObject in Inspector? [SOLVED]
//ButtonManager.js - Get user input from on-screen controls and pass along
var fireButton : GUITexture;
var actionButton : GUITexture;
var joyButton : GUITexture;
var actionOrient : GameObject;
var joyOrient : GameObject;
var actions = new GUITexture[4];
var destinations = new GameObject[4];
var feedback : GUIText;
As you can see, I have two variables, actionOrient and joyOrient, that are both GameObjects.
![Cannot_assign_GO][1]
Each variable is assigned properly in the Inspector; however, when I play my game I get the following error:
You probably need to assign the actionOrient variable of the ButtonManager script in the inspector. ButtonManager.Update () (at Assets/Scripts/ButtonManager.js:24) I get a similar error for the joyOrient variable if I comment out the actionOrient line. What am I doing wrong here? [1]: http://whitespacecg.com/Images/Cannot_assign_GO.pngUnassignedReferenceException: The variable actionOrient of 'ButtonManager' has not been assigned.
Answer by noradninja · Sep 24, 2011 at 04:27 PM
Turns out I had a duplicate copy of the script on the Main Camera. Deleted it and all is well again.
Facepalm.jpg
Facepalm x2 right here. Just had the same thing happen to me. $$anonymous$$ust've accidently dragged the C# script to another gameobject. Couldn't figure out why I kept getting 'unassigned' errors even though I properly assigned my intended GameObject. Thanks again.
Answer by Eric5h5 · Aug 28, 2011 at 05:22 PM
Maybe the variables were something else, like Transform, when you assigned them? And then you changed them to GameObject later without reassigning the variables.
I wish this was the case, but its not. I Wrote the script as is, then drag/dropped the assignments in the Inspector. Perhaps it is time for me to export the project files to a bundle, make a new project, and reimport the bundle, when Unity is 'funky' to me, this usually fixes things right up.
Your answer
Follow this Question
Related Questions
Bullet Prefab not instantiating 1 Answer
Issue instantiating an object with button click 2 Answers
how to link objects in the inspector on load level 1 Answer
Destroy a Gameobject with a UI Button 3 Answers
Restart button not functioning properly 4 Answers