- Home /
can't parent an Object, a second time.
I am getting the error.
Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
I have a gameObject(A) that I instantiate and child to another gameObject(B), that works no problem. But if I destroy gameObject(A) and then try to instantiate another gameObject(A) later I get that error. I am using the same method to instantiate both times.
whats causing this? what can I do to fix this? and is there any work arounds?
Whatever your code is doing, it is trying to use a prefab as a scene game object. Clearly there is a difference between your two scenarios, so full code of both would be needed to say exactly why.
To follow up on what $$anonymous$$ wrote, it looks like parenting is NOT the problem.
You should never want to change an prefab directly. The thing you spawn isn't a prefab -- it's a real thing copied form a prefab. The error says you changing the real prefab, by mistake.
So, I figured out different way to accomplish my end goal without destroying this obj and childing it.
But I am still interested to know where I went wrong. This is the code effecting it other then a Destroy(phone2) which gets called before this code gets called a second time. Also each time it gets instantiated, it is co$$anonymous$$g out as a (clone) of the prefab.
`public void RestartPhone(){
phone2 = Instantiate(Resources.Load("Phone"), transform.position, Quaternion.identity) as GameObject;
phone2.transform.parent = childTo;
phone2.transform.localEulerAngles = new Vector3 (292,0,0);
phone2.transform.localPosition = new Vector3 ( 0, -.4469702f, 2.367772f);
}
`
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Getting instance of an sub object rather than the original's subobject 0 Answers
Renaming Child Objects during Instantiate? 1 Answer
Instantiate Terrain Object as child of Empty Game Object 1 Answer
[SOLVED] How to make to clone an object and make it parent of the transform? 1 Answer