x


Instantiate example gives UnassignedReferenceException error

Blockquote> var cube : Transform; function Start () { for (var y = 0; y < 5; y++) { for (var x = 0; x < 5; x++) { var cube = Instantiate(cube, Vector3 (x, y, 0), Quaternion.identity); } } }

This example code from the Unity User Manual gives me an UnassignedReferenceException error. I have followed the directions in the tutorial exactly. I created a GameObject cube, then created an empty prefab, then I dragged the cube object to the empty prefab, renamed the prefab and dropped it onto the default reference for the var cube in the inspector for this script. But when I run the code, the system tells me that cube has not been assigned.

SOLUTION: You must click on the GameObject that holds the script in the hierarchy when you make the assignment, via drag and drop. If you have just clicked on the script itself (under Projects), it is POSSIBLE to do the assignment that way, but it doesn't work when your game runs.

more ▼

asked Oct 27 '10 at 05:31 PM

icemacsea gravatar image

icemacsea
61 5 5 7

Never mind! I went back to it and now it's working. Interesting that the physics acts a little differently with the prefab than it did with the "instantiate objects from scratch" example that preceded this one.

Oct 27 '10 at 05:47 PM icemacsea

The procedure is to write the answer and mark it accepted, rather than writing "solved" in the title.

Jan 29 '11 at 04:53 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

thanks!!! I was going crazy!

more ▼

answered Jan 29 '11 at 10:47 AM

nacho gravatar image

nacho
1

This isn't an answer.

Jan 29 '11 at 04:53 PM Eric5h5
(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:

x1677
x396
x119

asked: Oct 27 '10 at 05:31 PM

Seen: 1687 times

Last Updated: Jan 29 '11 at 04:53 PM