x


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 : /

more ▼

asked Jul 30 '11 at 06:40 PM

crump3ts gravatar image

crump3ts
1 5 5 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jul 30 '11 at 06:45 PM

testure gravatar image

testure
4.2k 20 25 48

The problem was close to that. I had it set to an actual GameObject (which I deleted later on), instead of the Prefab.

Thanks :3

Jul 30 '11 at 07:03 PM crump3ts
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2083
x1671
x1092
x69
x37

asked: Jul 30 '11 at 06:40 PM

Seen: 1573 times

Last Updated: Jul 30 '11 at 07:03 PM