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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by easilyBaffled · Mar 14, 2014 at 09:31 PM · public variableglobalvariablesunassignedreferenceexcept

Unassigned variable is assigned

I am having a strange bug. I have a couple public GameObject variables, and I have set them in the inspector. the enemy variable is fine, but the left_fist variable keeps giving me this error message.

 UnassignedReferenceException: The variable left_fist of 'Player AI' has not been assigned.
     You probably need to assign the left_fist variable of the Player AI script in the inspector.
     Player AI.forward_punch () (at Assets/Player AI.js:29)
     Player AI.Update () (at Assets/Player AI.js:24)


The strange thing is the function still executes, the fist moves. It doesn't come back, that's a separate problem, but it goes out. Does anyone know why I am getting the error?

 var enemy : GameObject;
 var left_fist: GameObject;
 var punching = false;
 var punching_forward = false;
 
 function Update () {
     var distance = Vector3.Distance(enemy.transform.position, transform.position);
     if(enemy.renderer.material.color == Color.red){
         gameObject.renderer.material.color = Color.blue;
     } else if(enemy.renderer.material.color == Color.blue){
         gameObject.renderer.material.color = Color.red;
     } else{
         gameObject.renderer.material.color = Color.green;
     }
     if(Input.GetKeyDown("space")){
         punching = true;
         punching_forward = true;
     }
     forward_punch();
 }
 
 function forward_punch(){
     if(punching){
         var current_fist_position = left_fist.transform.position;
         var distance_from_body = Vector3.Distance(transform.position, current_fist_position);
         if(punching_forward){
             if(distance_from_body < 5){ 
                 var new_position = (current_fist_position + transform.forward);
                 left_fist.transform.Translate(new_position * Time.deltaTime);
             } else { 
                 punching_forward = false;
             }
             Debug.Log(punching_forward);
             Debug.Log(distance_from_body);
             Debug.Log("");
             Debug.Log("");
         } else{
             if(distance_from_body > .5){
                 new_position = (current_fist_position - transform.forward);
                 left_fist.transform.Translate(new_position * Time.deltaTime);
             } else 
                 punching = false;
             }
     }
 }
Comment
Add comment · Show 5
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 getyour411 · Mar 14, 2014 at 09:58 PM 1
Share

What do you have in the left_fist Inspector slot? When you press Play, does whatever was there go away for some reason?

avatar image easilyBaffled · Mar 14, 2014 at 10:01 PM 0
Share

I have a game object there. It's just a cube. It's there I can see it and I can mess with it. The code works for the most part I just keep getting that error message.

avatar image TykoX64 · Mar 19, 2014 at 03:12 PM 0
Share

I got the same error message in one of my games. it said that a transform wasn't set that I had set in the inspector. Ultimately I ended up ignoring it since the game ran just fine both in editor and in build. I think the editor is just confused, but if there's something else I'd love to know why it's doing it.

avatar image robertbu · Mar 20, 2014 at 03:07 PM 2
Share

If you are absolutely sure that the 'left_fist' exists at both while the app is not playing and during play, then the most likely issue is that you have this script attached to more than one object. In the upper right of the Hierarchy, there is a search field. Type the script name into that field to see if you have other objects with this script.

avatar image easilyBaffled · Mar 20, 2014 at 05:11 PM 0
Share

@robertbu you got, I accidentally put it on the fist too. $$anonymous$$ove your comment to the answer and get your vote.

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

21 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

Related Questions

unassignedreferenceexception - script used in multiple scenes 0 Answers

UnassignedReferenceException: The variable enemy of EnemiesSpawner has not been assigned unity3d 0 Answers

cashing in Scenes to a public vaiable 1 Answer

Shift-Click on Scene View to add Vector2 0 Answers

Is it possible to define a public variable of type UnityEngine.Object? 0 Answers


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