I get that error when I try to run this code:
GameObject x = (GameObject)Instantiate(cube, transform.position, transform.rotation);
The strange thing is, I have the exact same thing in another script, and it runs : /
Jul 30 '11 at 06:40 PM
Jul 30 '11 at 06:41 PM
what is cube? make sure it's not null.. if you're trying to instantiate a primitive cube (not a prefab named 'cube') then you need to use GameObject.CreatePrimitive instead.
Jul 30 '11 at 06:45 PM
The problem was close to that. I had it set to an actual GameObject (which I deleted later on), instead of the Prefab.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
Once you sign in you will be able to subscribe for any updates here
Answers and Comments
The best place to ask and answer questions about development with Unity. Check out our FAQ for more information.
To help users post good questions and use the site effectively we have posted a tutorial video. Please check it out.
asked: Jul 30 '11 at 06:40 PM
Seen: 1573 times
Last Updated: Jul 30 '11 at 07:03 PM
how to instantiate object when I click
Referencing instantiated objects at runtime
Reference by Instance ID?
Destroy the current GameObject?
Instantiate and destroy on given location
What should I change in this instantiating a GameObject in a script using Unity?
object not spawning but no error message
C# cast object to gameobject not working
How to correctly convert Object to GameObject
Cannot instantiate gameobject