- Home /
Not your typical "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption"
Hi guys,
I am having a bit of an issue with parenting a freshly instantiated prefab. In one specific script only, I get the "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption" error every time I try to assign a parent. Changing transform.position or transform.localposition is simply ignored.
I have tried addressing both GameObjects and Transforms in my Instantiate, with the same results.
Through the rest of the game I'm working on, I run pretty much identical code on a number of scripts, and they all work flawlessly. This single script, however, for some reason fails.
For the last hour or so I've been googling this error message, and it's typically caused by someone trying to access the prefab instead of the object they spawned. This is not the case. I can see the spawned object in the Hierarchy, but for some strange reason, Unity insists on treating them like uninstantiated prefabs, even though I can see them right there in the game Hierarchy.
Can anyone help? Here is the snippet of code in question:
public class pickup_points_3 : pickup_base
{
public PointValues PointValue;
private int[] Values;
private int _actualValue;
private Material actualMat;
public GameObject[] thePrefabs;
private GameObject[] theObjects;
//public Renderer TheColouredRenderer;
public void SetItUp()
{
EnableSetup();
theObjects = new GameObject[thePrefabs.Length];
for (int i = 0; i < thePrefabs.Length; i++)
{
theObjects[i] = Instantiate(thePrefabs[i], transform.position, Quaternion.identity) as GameObject;
theObjects[i].transform.parent = transform;
theObjects[i].SetActive(false);
}
EnableGraphics();
SetupValues();
SetValues((int)PointValue);
}
Stuff that has nothing to do with the instantiation.
}
Your answer
Follow this Question
Related Questions
Setting parent of instantiated object fails (Error: setting parent of prefab is disabled...) 1 Answer
problem whit Instantiate Prefabs position. 0 Answers
Prefabs Transforms LookAt 0 Answers
How do I Update the transform of Instantiate prefab? 2 Answers
Instantiate prefab as child at a transform? (Javascript/Uniyscript) 2 Answers