How can I change the root game object of a prefab in the editor?
I have a prefab containing a gameobject with a child. Now I need to make a gameobject as the root and make it the parent of the current root. How do I do that?
I already tried much, although I didn't find anything. I even changed the prefab files with a text editor, unity crashed every time though :D
How do I do that in the editor?
Answer by Mac70 · Oct 08, 2019 at 09:03 PM
I know it's the question asked long time ago, but I hope this helps:
There doesn't seem to be any built-in approach to it as of now. You can follow these steps in order to get around it:
Create new GameObject, make it child of prefab root.
Copy all components you want to copy from old root to this new GameObject.
Move all chidren from old root to this new GameObject.
Done! Your new GameObject now have the same functionality your old root had, and you can use root in any way you want.
Thanks, this helped. As a slightly quicker way 1. Do Ctrl-D (duplicate) on your prefab root. This will create a new Game Object with all the correct components & settings as a child of the current prefab root.
2. Delete all of the components from the prefab root except the Transform/RectTransform (basically converting this back to an Empty object) 3. (Optional) Add any desired new components to the prefab root to change it to what you want