Hi, while working with unity, I get a “null reference exception Object reference not set to an instance of an object” error.
I got this method inside the “SpawnObjects” class :
public class SpawnObjects : MonoBehaviour
{
public GameObject[] RandomGO;
public void spawnSomeObjects()
{
GameObject Gobj = Instantiate(RandomGO[0]) as GameObject;
Gobj.transform.position = new Vector3(0f, 50f, 5f);
}
}
After setting the lenght of the array and after placing the objects in it from the inspector, I try to call this method from the Update function of this other class :
public class BucketMovement : MonoBehaviour {
public float AssignTimeSpawn = 2.0f;
float TimeSpawn = 2.0f;
SpawnObjects So;
void Start()
{
So.GetComponent<SpawnObjects>();
}
void Update ()
{
TimeSpawn -= Time.deltaTime;
if (TimeSpawn < 0)
{
TimeSpawn = AssignTimeSpawn;
So.spawnSomeObjects();
}
}
And as I said, I get that null reference exceptions… question : if I set field members to public static, why they wont appear in the inspector?
I cannot use the gameobject.find( “” ).getcomponent solution since the object that i’m looking to call will be instantiated at runtime, after the selected timelapse, and will still give me the same error