Error of Empty Prefab when try to instantiate it (with VIDEO):
Hello Guys, I am traying to instantiate an prefab by script but there is an error. I did not attached it’s script to a GameObject because of my architeture, but instantiate it by an other instantiated class. Look:
Main Camera<<Controle(Control Class)<<Planta(Map)<<Parede(Wall)<<parede:Prefab(Prefab)
It does no instantiate my wall in desired position.
ArgumentException: The prefab you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:71)
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:52)
Parede.adicionaValores (Int32 altura, Int32 largura, Int32 posicaoX, Int32 angulo) (at Assets/Scripts/Parede.cs:26)
Planta.addParede (Int32 altura, Int32 largura, Int32 posicaoX, Int32 angulo) (at Assets/Scripts/Planta.cs:15)
Controle.Start () (at Assets/Scripts/Controle.cs:14)
The idea of the project is to build a house. When I press some button I send information like scale,etc and it instantiate it in a Array of scripts ‘wall’ (with the prefab inside them) inside my house map class(I don’t know exactly how to translate it). I don’t know why it’s giving me this error (it’s in video) but before someone ask why I am putting script inside Prefab and not the opposite, its because this class must have an array of furnishings, that are accomplish to it, and receive some of it’s values. Thanks!
public class Controle : MonoBehaviour {
Planta planta=new Planta();
void Start () {
// Altura//Largura/Posição/Angulo
planta.addParede(10,100,0,0);
}
}
public class Parede : MonoBehaviour {
private int altura;
private int largura;
private int posicaoX;
private int angulo;
public Transform parede;
Revestimento revestimento = new Revestimento();
public void adicionaValores(int altura,int largura,int posicaoX,int angulo)
{
this.altura=altura;
this.largura=largura;
GameObject newObject= Instantiate(parede, new Vector3(posicaoX, 0, 0), Quaternion.Euler(angulo,0,0)) as GameObject;
newObject.transform.localScale+=new Vector3 (altura, largura, 0);
}
}
public class Planta : MonoBehaviour {
public List <Parede>paredes= new List<Parede>();
Parede parede=new Parede();
public void addParede (int altura,int largura,int posicaoX,int angulo) {
parede.adicionaValores(altura,largura,posicaoX,ang ulo);
paredes.Add(parede);
}
}
The video of error: