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 /
avatar image
0
Question by gabriel · Apr 22, 2011 at 12:29 AM · errorreferenceexceptionunassignedreferenceexcept

Help with error: UnassignedReferenceException

Edit, I assigned references to both Flames, and the message keeps poping up.

alt text

This is the error:

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

This is the script:

//Turret control script

var target : Transform; var range = 10.0; var leftFlame : GameObject; var rightFlame : GameObject;

static var mode = "idle";

function Awake() { target = GameObject.FindWithTag("Player").transform; leftFlame.renderer.enabled = false; rightFlame.renderer.enabled = false; }

function Update () { if(target && CanAttackTarget()) { //transform.LookAt(target); var targetRotation = Quaternion.LookRotation(target.position - transform.position, Vector3.up); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 1.2); } }

function CanAttackTarget() { //check if the target is close enough if(Vector3.Distance(transform.position, target.position) > range) { Disengage(); return false; }

 var hit : RaycastHit;

 //check if there is collision inbetween turrent and target
 if(Physics.Linecast(transform.position, target.position, hit))
 {
     if(hit.collider.gameObject.tag != "Player")
     {
         Disengage();
         return false;
     }
     else
     {
         Attack();
         return true;
     }
 }
 return true;

}

function Attack() { if(mode != "attack") { InvokeRepeating("FalconAnimate", 2, 0.05); mode = "attack"; } }

function Disengage() { if(mode != "idle") { CancelInvoke(); mode = "idle"; leftFlame.renderer.enabled = false; rightFlame.renderer.enabled = false; } }

function FalconAnimate() { if(leftFlame && rightFlame) { if(leftFlame.renderer.enabled) { leftFlame.renderer.enabled = false; rightFlame.renderer.enabled = true; } else { leftFlame.renderer.enabled = true; rightFlame.renderer.enabled = false; } } else { print("Effects on turrent not set!"); } }

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

5 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by corpsinheretoo · Mar 31, 2014 at 05:05 AM

I was having the same problem and this thread helped me out. But I would like to restate clearly my mistake so that it is clear for others:

I was dragging my prefab (from the project view) onto the inspector while having selected the script in the project view (which is wrong);

this looks like it works (the prefab name shows up in the variable slot) - but does nothing. I guess this was sort of like combining blueprints; instead, I dragged my prefab (again from the project view) onto the inspector while the instance of my script (in the scene hierarchy) was selected. Then all was good again :).

Comment
Add comment · Show 3 · 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 einzweidrei · Feb 25, 2015 at 07:57 PM 1
Share

Thanks man! I was banging my head around for days and when I applied the solution everything was good. :-)

avatar image Anton1274 · May 15, 2015 at 01:35 PM 0
Share

Tanks it works....

avatar image snookerc · Oct 24, 2015 at 02:47 AM 0
Share

O$$anonymous$$G thank you!! You saved me even more hours of confusion!!!

avatar image
0

Answer by DaveA · Apr 22, 2011 at 12:40 AM

Did you do that, assign the leftFlame variable of the TurretControl script in the inspector?

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 Peter G · Apr 22, 2011 at 12:50 AM 0
Share

You'd be surpised how many times he has to be told that. time.http://answers.unity3d.com/questions/54110/how-to-disable-errors-in-the-console/54112#54112

avatar image gabriel · Apr 22, 2011 at 01:20 AM 0
Share

Im doing this with a Tutorial, and the guy never assigned anything in the inspector from what I can tell.

avatar image
0

Answer by Gabriel 5 · Apr 22, 2011 at 01:03 AM

Im doing this with a Tutorial, and the guy never assigned anything in the inspector from what I can tell.

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 Peter G · Apr 22, 2011 at 01:42 AM 0
Share

He must have meant to because the code seems to assume that you do because there are 0 checks to see if there is a reference and/or find the reference if there is not. I would try assigning the reference in the inspector.

avatar image gabriel · Apr 22, 2011 at 05:59 AM 0
Share

I edited the post, I assigned references, but the problem persists.

avatar image
0

Answer by eloka · Jul 14, 2011 at 10:00 AM

had that problem too here is what i did. i included a new variable 'x' and assigned the false value in my function update and then changed its value so it doesnt update its value again.


var target : Transform;

var range = 10.0;

var leftFlame : GameObject;

var rightFlame : GameObject;

var mode = "idle";

var x = "t";

function Awake()

{

      target = GameObject.FindWithTag("Player").transform;
      
      

}

function Update ()

{

if( x =="t")

{

  leftFlame.renderer.enabled = false;
 
      rightFlame.renderer.enabled = false;
 
      x="s";
 

}

Comment
Add comment · 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
0

Answer by Brian1957 · Aug 03, 2013 at 05:50 PM

Should it be of help, I have just resolved my 'UnassignedReferenceException'. For those using the same book. To cut a long story short, the solution was that, I have a bullet prefab, an explosion prefab and a moveBullet scipt. The moveBullet script was changed to show the explosion prefab. You will easily see the explosion variable displayed at the top of the inspector window and will have dragged and dropped the explosion prefab to the variable. Now you will have to go back to the original bullet prefab find the same movebullet script in the inspector window for that prefab and add the explosion prefab to the script a second time. N.B. I am a total beginner and the book is Holistic Game Development with Unity

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

NullReferenceException - With Network PlayerSpawn 0 Answers

Null Reference Exception Error 1 Answer

NullReferenceException: object not in inspector? 0 Answers

Stupid "Reference Exception Error" 1 Answer

Despawner script returns null reference exception. 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