In the process of copying my game working files from one computer to the other (via SVN), I somehow lost my prefab connections. This was a huge problem for me as I had nearly 1000 prefabs, possibly more. Initially I started adding in replacement prefabs and copying over the position, rotation and scales of the regular gameObjects but that process was taking far too long.
Here’s a much quicker way of converting a bunch of nearly identical (except position, rotation and scale) GameObjects into prefabs.
First, create the prefab of the finalized object. Select it and then drag the final gameObject into the Project view to create the prefab.
Select the prefab in the Hierarchy window. The text of the prefab is blue, however the colour changes when it is selected like below.
Count the number of non-prefabbed gameObjects you’d like to replace and duplicate the existing prefab by the same number.
Drag each prefab into the original gameObjects to add it as a child. Do this for each prefab and each gameObject you wish to replace. I’d recommend expanding the non-prefabbed gameObject so you can remember which ones you have already done.
Now that you have the prefabs in the original GameObjects, you can quickly reset the position, rotation and scale. Set the position and rotation all to 0 (zero) and scale to 1. Note: The TAB key on your keyboard is definitely your friend here. You can do each prefab in less than 3 seconds. Do this for each of the prefabs
Select all the prefabs. You can multiple select by holding down the CTRL key while clicking on each prefab.
Drag the selected prefabs to the location that you want them to be. For example the parent object.
Your prefabs are now no longer children of the original gameObjects you were using.
To remove all the original non-prefab gameObjects, select them by holding down the CTRL key and clicking on each one. You can also select the top gameObject, hold Shift and then click the bottom gameObject too.
Press the delete key on your keyboard to remove them. You’re now left with a series of prefabs that have replaced your original gameObjects.
This all will, of course, only work for gameObjects that are identical with the exception of their position, rotation, and scale.
Leave a Reply