- Home /
The referenced script on this Behaviour is missing!
var health1 : Texture2D; //one lives left var health2 : Texture2D; //two lives left var health3 : Texture2D; //full health
static var LIVES = 3;
function Update () { switch(LIVES) { case 3: guiTexture.texture = health3; break;
case 2:
guiTexture.texture = health2;
break;
case 1:
guiTexture.texture = health1;
break;
case 0:
//gameover script here
break;
}
}
var speed = 3.0; var rotateSpeed = 3.0; var bullitPrefab: Transform; private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "fallout") { dead = true; //substract life here HealthControl.LIVES -=1; } }
function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") rotateSpeed, 0); var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
}
}
function LateUpdate() { if(dead) { transform.position = Vector3(0,4,0); gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10); dead = false; } }
@script RequireComponent(CharacterController)
After I made this scripts, I get the "The referenced script on this Behaviour is missing! " Warning...
Is the script actually connected to a game object? Sometimes unity seems to lose the connections.
Answer by Bunny83 · Apr 29, 2011 at 09:17 PM
I don't think that this have anything to do with the content of this script. This error occurs when you have a script attached to a gameobject and you deleted, moved or renamed it outside of unity. Unity can't find the related script for the MonoBehaviour component.
If you want to rename or move a script do it always in Unity. To solve your error, just find the component that references this missing script and drag the right script onto the component.
Answer by Bovine · Sep 14, 2011 at 10:30 AM
I had this issue recently. For me the message appears when I run the game and it will only highlight the GameObject with the missing script if it is in the current scene.
I was able to load different scenes after running it and I was able to find the offending GameObjects.
For anyone caught out by this. pause the game play when the warning appears. highlight the warning in your console. look in your hierarchy - Unity does highlight the problem item in the hierarchy once you click on the warning in the console. you'll then see the script is simply missing. As Bov says it has to be the current scene, so pause the game is scenes are changing quickly.
Thanks. I've tried pausing and highlighting the error, but it does not work for me. Any other ideas?
It is caused by a missing behaviour. Clicking the error while the object is alive is the only way to find it besides manually checking everything. Are you dynamically destroying objects? It might only exist for long enough to throw the error. Enable the 'Pause on error' option in the console window (control+shift+C) and the game should stop before the object disappers. If not, you'll have to check your instantiable objects and see which one is missing a script.
Answer by Tekksin · Mar 05, 2015 at 12:38 PM
If you're having trouble finding where the error is coming from (sometimes unity doesn't highlight it, especially in cases where the gameobject is turned off), what works best for me is duplicating the scene where the error appears, and deleting chunks of the duplicated scene, until I get down to the last few gameobjects (run the scene each time you delete something to see if the warning goes away. If it does, then undo and delete other game gameobjects while inspecting the apparent culprit(s)). Once I find the problem, I just remove the component from that game object, save the prefab, and delete the duplicated scene.
This is a bit complex. The easier way is using this plugin.
I did that. I have an empty scene and I still have the warning haha. No idea what is going on
Answer by PFC-Ben-W · Jan 02, 2020 at 01:58 PM
In case you get this error, while preloading the next szene with the AsyncOperation : If you have in the preloaded Szene any Objects or components, that are missing, the present scene will print out all the errors of your next preloaded szene. So in that case, it would be better, to check your next szene, otherwise you will never get clear on that.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130314im_/https://answers.unity.com/themes/thub/images/avi.jpg)