- Home /
What's the cause of "The referenced script on this Behaviour is missing!" in my script?
Hi people! I'm having a problem with my script and i tried everything to end the warning message but I couldn't find what's the cause. I have these two scripts in my scene:
using UnityEngine;
using System.Collections;
public class CharacterAssets : MonoBehaviour {
public GameObject[] characterMesh;
void Awake ()
{
DontDestroyOnLoad(this);
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}
and...
using UnityEngine;
using System.Collections;
public class Customize : MonoBehaviour {
private int characterMeshIndex = 0;
private string charMeshName = "Warrior";
private CharacterAssets scriptCA;
// Use this for initialization
void Start ()
{
scriptCA = GameObject.Find("CharacterAssetManager").GetComponent<CharacterAssets>();
InstantiateCharacterMesh();
}
void OnGUI()
{
ChangeCharacterMesh();
}
void InstantiateCharacterMesh()
{
switch(characterMeshIndex)
{
case 1:
charMeshName = "Hunter";
break;
case 2:
charMeshName = "Rogue";
break;
default:
characterMeshIndex = 0;
charMeshName = "Warrior";
break;
}
if(transform.childCount>0)
{
for(int cnt=0 ; cnt < transform.childCount ; cnt++)
{
Destroy(transform.GetChild(cnt).gameObject);
}
}
GameObject mesh = Instantiate(scriptCA.characterMesh[characterMeshIndex], transform.position, Quaternion.identity)as GameObject;
mesh.transform.parent = transform;
mesh.transform.rotation = transform.rotation;
}
void ChangeCharacterMesh()
{
if(GUI.Button(new Rect( Screen.width/2-60 , Screen.height-40 , 120 , 30),charMeshName))
{
characterMeshIndex++;
InstantiateCharacterMesh();
}
}
}
so... the problem is a warning that appears every time that i call the function "InstantiateCharacterMesh" on the second script.
The warning says: The referenced script on this Behaviour is missing! UnityEngine.Object:Instantiate(Object, Vector3, Quaternion) Customize:InstantiateCharacterMesh() (at Assets/Scripts/Customize.cs:47) Customize:Start() (at Assets/Scripts/Customize.cs:14)
The game run and works ok but this warning message is pissing me of! If i simply comment the lines 47,48 and 49, the error disappears(but the code become incomplete i don't do the most important thing that is the instantiate).
Are you populating the GameObject array in CharacterAssets via the Editor? Sounds like at least one of those objects has lost a reference to an attached script. You should be able to view each in the Inspector and fix any missing scripts that way if so.
Thanks man, the error was exactly in the prefabs that I used to put in this array! Each of these objects had a script component (monobehaviour) with a message of missing script. I deleted this component on these objects and the message of warning is gone, thanks man!
Answer by iwaldrop · Apr 19, 2013 at 01:42 AM
Indeed, this error doesn't come from script, but rather because there is a component on a game object that doesn't know what script it is supposed to use. You probably renamed a script from outside of Unity or something...
Usually you can double-click that error message and it'll take you to the GameObject in question. Hopefully you can remember whats supposed to go there.
thanks for the answer, in one of the objects that I used in the array had a missing script!
Your answer
Follow this Question
Related Questions
Reference script on Behaviour is Missing, but IT'S NOT MISSING 0 Answers
The referenced script on this Behaviour is missing! 0 Answers
Missing Behaviours still process as if they exist? 0 Answers
Free Camera 2 Answers
Spawned units disappear 2 Answers