- Home /
Question by
crump3ts · Jul 30, 2011 at 06:40 PM ·
gameobjectinstantiateobjectcastinvalidcastexception
Cannot cast from source type to destination type
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 : /
Comment
Best Answer
Answer by testure · Jul 30, 2011 at 06:45 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.
The problem was close to that. I had it set to an actual GameObject (which I deleted later on), ins$$anonymous$$d of the Prefab.
Thanks :3