"The Object You Want To Instantiate is Null" but nothing is wrong the error is not effecting anything
I'm getting this error and I've seen all the stuff on it online. The weird thing about it in my case is that it is not causing any problems. Everything is working as intended. However, the message still shows up in the console whenever I run the scene. As far as I can tell though, my object spawns fine, with all the given parameters, runs its scripts and everything goes smoothly. The error message is still there though. Things I have tried: - Making sure Instantiated object is instantiated as a gameObject - Making sure the prefab I want to instantiate is already a GameObject in the script and that it is loaded in start() from resources before it is instantiated - Restarting Unity I've attached all relevant sections of the code. spawnClick() is called with 1 parameter in Main()
GameObject ClickWall;
GameObject HoldWall;
GameObject SpinWall;
void Start () {
ClickWall = Resources.Load ("wallClick") as GameObject;
//HoldWall = Resources.Load ("wallHold") as GameObject;
Main();
}
void SpawnClick(float theta, int hp = 1, float tMax = 3f, float omega = 0f) {
//theta = theta * (Mathf.PI) / 180f;
GameObject wall;
Vector3 pos = new Vector3 (0f, 0f, 0.7f);
wall = Instantiate (ClickWall, pos, Quaternion.Euler(0f,0f,theta)) as GameObject;
wall.GetComponent<ClickWall>().maxT = tMax;
wall.GetComponent<ClickWall> ().maxHP = hp;
wall.GetComponent<Rigidbody2D> ().angularVelocity = omega;
}
Try to add this and see if it works->
void SpawnClick(float theta, int hp = 1, float t$$anonymous$$ax = 3f, float omega = 0f) {
//theta = theta * ($$anonymous$$athf.PI) / 180f;
GameObject wall;
Vector3 pos = new Vector3 (0f, 0f, 0.7f);
if(ClickWall == null) //add this
ClickWall = Resourses.Load("wallClick") as GameObject; //add this
wall = Instantiate (ClickWall, pos, Quaternion.Euler(0f,0f,theta)) as GameObject;
wall.GetComponent<ClickWall>().maxT = t$$anonymous$$ax;
wall.GetComponent<ClickWall> ().maxHP = hp;
wall.GetComponent<Rigidbody2D> ().angularVelocity = omega;
}
And remove from Start() the ClickWall = Resources.Load ("wallClick") as GameObject; If it is fixed means that it gets Unloaded by UnloadUnusedAssets() at some point before you instantiate it. If not i have no clue! Cheers.