Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Like in question, I want to create multiple object from the same prefab in for loop. Something like this:

    for(int i = 0; i < 4; i++)
    { GameObject Orb = (GameObject) Instantiate (OrbPrefab, transform.GetChild(i).position, Quaternion.identity);
    //code to do something with Orb
    }

But I don't know why I get this error: "Object reference not set to an instance of an object"

share|improve this question

put on hold as off-topic by Josh Petrie 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

    
1  
In this case, it could be OrbPrefab or transform.GetChild(i) that's null. You should absolutely spend a day learning how to use the debugger. Look for tutorials on using the debugger in Unity. – Byte56 2 days ago