- Home /
How to add a prefab back to a gameobject that is missing one?
I opened my scene in Unity and my character model has dissapeared. However, I still have the prefab in my project, can i some how re-attach this back to the GameObject?
Answer by TomYeti · Aug 27, 2019 at 08:03 PM
I've solved this same issue today, and I want to offer a little bit more thorough and updated response.
My issue was similar, I had prefab instances somehow tied to the wrong prefab, which i deleted. The new prefabs in my project were identical fbx files I had imported.
Assuming you have "Force Text" enabled for Asset Serialization, you can do this:
Open your scene with broken prefab instances in your IDE of choice. For me, that's VS code. It should be a YAML file.
Back in Unity, find the name of the prefab that is broken. Mine was "FTC_DZ_ALL_Terrain". Make sure these names are unique, if they aren't, rename a duplicate that isn't missing.
Back in your IDE, use the "Find" tool to find that name. Only one object should have it.
You will find a line that says "value: FTC_DZ_ALL_Terrain". The parent of that line should read "-target: {fileID: [some numbers here], guid: [guid goes here]}" and possibly other things. You want to know the guid. Copy that guid. For instance "d09aaea6fade35141905fd9dd33b5c51"
Open up find and replace. paste that guid in the find category.
Now, navigate to the prefab in your project you want to replace this object with. Open the ".meta" file associated with that prefab. ie, if your prafab is named "MyPrefab.prefab", open the file titled "MyPrefab.prefab.meta"
Find the line that says "guid" near the top and copy the guid.
Back in your scene file, paste that guid in the "Replace" field of your find and replace.
Press "Replace all" to replace all occurances with that
To check if it was successful, save your scene file and open it in Unity. Hit "Reload" if prompted.
Viola!
I'm not sure if it handles nested prefabs perfectly, you may need to replace more than just the parent GUID. But so long as you're replacing the right guids, it should all work out.
Answer by Alex_May · Sep 23, 2015 at 05:33 PM
Try this replace objects with prefab script. It saved my bacon the other day.
I appreciate the link, and it will work for some cases. I'll add for the next person that the shortco$$anonymous$$g is that any property overrides will be lost. So in my case, I use ProBuilder objects that store a different mesh as an override of the property. The code in the script above doesn't have a way to copy this kind of data.
I am a noob when it comes to unity. How do I run the missing prefab script?
@briggs, you might have to do a bit more code changes beyond this, but using the linked code as a starting point: 1. Change HydraEditorWindow to EditorWindow (from UnityEditor namespace). 2. To open the editor window, call code like GetWindow<ReplaceGameObjects>();
If that doesn't work well, consider that you don't need the editor window stuff at all. You just need to call the Replace()
function passing in the right params. You can make a simply MonoBehavior-based class with some properties to do that. Just understand that the code must run in edit mode and not play mode.
Answer by colakovicrajko · Aug 24, 2020 at 09:48 PM
For me this issue was solved by going to Assets (at the top toolbar), then clicking Reimport All.
It happened after using Git to switch from my Ubuntu computer to my macbook.
Anyone, before trying the first answer (which in my (and most!) case would be more troublesome than rebuilding the whole project from scratch), please do yourself a favor and try this solution first, and then send @colakovicrajko a virtual hug.
It took a click and a few seconds for all my missing prefabs to get fixed. Thank you very much! :)
Answer by IT_Criminal · Nov 23, 2012 at 02:21 PM
1) in the hierarchy view click on the bugged game object
2) in the inspector view click on "Revert" to reset the game object to prefab settings
3) tell me if it worked
I recently added many game objects to organize the hierarchy of scenes, but after others checked out my changes, they saw missing prefabs for many game objects whose prefab I had swapped. Everything is fine in my original working directory, but I see the missing data when I checkout the project anew. When I select a $$anonymous$$issing Prefab object, there are no "Apply, Select, Revert" buttons in the Inspector.
Answer by oigetinthevan · Sep 11, 2021 at 07:21 PM
This may not solve this particular case of missing prefab, but for me, I had a game object in a prefab that was supposedly missing after pulling from my repo.
Opening the original prefab and toggling the enable/ disable button on a component in the "missing object" fixed all instances of this problem for me.
Hope this helps.