Setting the transform of an instantiated game object

Hello! I am new to posting on Unity Answers, though I have been stalking the threads for answers to my problems for quite sometime now… :wink:

I am having an issue setting the transform of a game object that I have already instantiated. Now I’ve seen several threads already where people have similar issues, but they are all trying to change the transform of the prefab. I have instantiated the prefab into a variable and I am trying to change the transform of that variable. Here is the bit of code that I am talking about.

var single : GameObject;
private var temp:GameObject;

temp = GameObject.Instantiate(single, location, single.transform.rotation) as GameObject;
temp.transform.parent = transform;

The really frustrating part is that I’m doing this somewhere else in my code (what I believe to be the exact same thing) and it works. This one however…does not.

Also, the exact error I am getting:

“Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.

Thanks a lot for any help!

Just giving it a once over it seems like this might be the type of line that you’re looking for.

    temp = GameObject.Instantiate (single, transform.position, transform.rotation) as GameObject;

But is “location” in your above code another variable that you haven’t written down above next to single and temp? I’m not really sure why that’s there. :stuck_out_tongue: