|
I tried transform.parent = desiredParentTransform but unity gives me an error saying that parenting a prefab is disabled to prevent data corruption. What do I do?
(comments are locked)
|
|
you can not make a prefab parent of another and a prefab can not have a parent at all. in editor if you drag something on a prefab it will change the content of that prefab with the newly draged gameObject. if you want to change the parent of a prefab you should instantiate it and change the parent and then create a prefab from it again. in runtime you don't have access to editor classes and methods but in editor scripts you can do this easily. to create a prefab in a script you should use CreateEmptyPrefab and then assign a Gameobject to it by ReplacePrefab. so just instantiate the prefab, then do whatever you want. (add or remove components, change parent) and then apply to prefab. I think this solution defeats the purpose of using Prefabs. The right way to do it is explained here by user "Slem."
Mar 25 at 09:08 PM
swatmaster69
(comments are locked)
|
|
The only workaround I know about this is the following:
If you just instantiate the prefab and set the instance's parent, it'll work fine. The issue in the question was that he was trying to set the prefab's parent, not the instance's one
Nov 16 '10 at 11:59 AM
Mike 3
(comments are locked)
|
|
I'f you'd let me reply the Quality in Q&A with Quality = q and Qq = Aq then I would say: Just don't parent the prefab because it is a bad way to do what you want in any case. Make a clone with the Instantiate method Instantiate(PREFAB, TRANSFORM (pos), ROTATION)
(comments are locked)
|
|
Do you have a prefab that has not been instantiated yet? For example, do you have a class that has a public GameObject variable that you drag/drop the prefab onto? If so, you'll need to do one of two things (depending on how your game works). Either instantiate the prefab (http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html) or create an instance of the prefab in your scene by dragging it into the scene and then dragging the prefab instanace in the scene onto your script. Here's an example of instantiating a prefab you've dragged onto your script that doesn't exist in the scene until runtime.
(comments are locked)
|

Could you provide some more information on what your current setup is vs. the desired one?