- Home /
Problem adding a Parent to a Instantiated Object
Hey guys! I'm trying to instantiate a GameObject and setting it's parent afterwards. The error I'm getting is: "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption".
I know that I shouldn't change the parent of the prefab, but of the instance itself. And that's exactly what I'm doing.
What am I doing wrong? Is this just some dumb mistake I'm not seeing?
Thank you very much for your help!
Answer by sas_88 · Jul 16, 2015 at 06:36 AM
Add the script to which the instantiate
GameObject instance =Instantiate(myVisualEffect) as GameObject;
Try this
instance.transform.SetParent (this.transform);
I've tried that before but, just to be sure, I tried it again. It gives me the same result. :/
Add the script to the canvas which i have followed & works fine 4 me.
$$anonymous$$eep the prefab in Resources folder.
The script which i have used
GameObject instance =Instantiate(Resources.Load("Instan")) as GameObject;
instance.transform.SetParent (this.transform);
instance.transform.localPosition = new Vector3 (70f, -15f, 0.0f);
Output of above script is