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!

Add the script to which the instantiate

GameObject instance =Instantiate(myVisualEffect) as GameObject;

Try this

instance.transform.SetParent (this.transform);