-1
\$\begingroup\$

I have a Game Object called 'car' in my Assets folder. I have this code in C# unity to instantiate it.

GameObject car; 

    void Start () {

        Vector3 position = new Vector3(5, 5, 5);

        GameObject newGameObject = Instantiate(car);

        newGameObject.transform.position = position;

    }

And I get this error - 'the thing you want to instantiate is null'

What might be the problem ?

\$\endgroup\$
1
  • 2
    \$\begingroup\$ It should be pretty clear.. you're trying to instantiate null.. so car is null.. you need to assign something to car? (Drag your asset to the car property in the inspector) \$\endgroup\$
    – bummzack
    Mar 27, 2015 at 6:50

1 Answer 1

1
\$\begingroup\$

The GameObject car is not set to anything. That means it's null. This is exactly what the error message is telling you. Just because you happen to have a prefab named 'car' in your Assets folder doesn't mean you can name a variable car and expect Unity to know you're talking about the same thing.

See my answer to your other question to learn one way to instantiate a prefab.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .