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.
– whebertThanks 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!
– 3dMaia