Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to restore broken prefab?

Discussion in 'Editor & General Support' started by leegod, Feb 23, 2017.

  1. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,472
    as following image,

    somewhat big canvas prefab broken. I don't know why this happen.

    This contains all of my UI work of past month.

    I should recover this. plz...

    problem23.PNG
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Easiest would be if you have it in version control.
    Next would be if you use text serialization, have a look at the file in a text editor and check if it contains gameobjects and components.

    How did the file break? can you reproduce what you did?
     
  3. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,472
    So the situation was, I worked outside at my laptop with ADATA SE730 external SSD. And after work done, saved scene, project. No problem at all.

    Came back to home at night, connect SSD to desktop USB 3.0, run unity (same version with my laptop, newest beta, 5.6.0b9), open project, but error message appears that some library file failed or corrupted?

    Tried many times, but after some auto-importing, it failed, I forced quit.
    SSD drive said it has problem and recommend drive error repair process(Window 10 message), so I did.

    And tried again, and it opened, but worked and saved scene file size now become 1kb and no objects there in hierarchy.

    And sometimes (this same happened few days ago with my previous SSD, samsung portfolio, so I changed SSD, but same occured...) some one script completely changed to unknown characters (like unicode or whatever) and now above Canvas prefab become like that and can't be used.

    Here I attached canvas prefab.
     

    Attached Files:

  4. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Hate to bring up a 3 year old thread but something similar happened to me and this seems to be the most recent case I can find.

    2019.3.0f6

    Had a complex third person controller prefab in scene, was making many changes in scene in edit mode. After many changes I apply the prefab changes from the object in scene. Have done this many times with the same object with no problem.

    This particular time I had manually added a component, but then removed (it was marked as removed in the editor), then added the same component via a menu option since it was a 3rd party component (in this case a ragdoll feature).

    I then went to apply the prefab changes, Unity crashed and when re-opened the prefab was broken in assets (showing the white icon the OP's image) and the prefab in scene was red with all child objects listed as "Missing Prefab (Dummy)".

    I was able to recover it by simply duplicating the prefab in my assets folder (select the prefab and use CTRL+D). So far it is working fine and seems to have the latest changes I made when the save previously crashed.
     
    Last edited: Sep 15, 2022
    Zenphx, emredesu, FStein and 2 others like this.
  5. Jonatan07

    Jonatan07

    Joined:
    Mar 25, 2018
    Posts:
    1
    I have the exact same issue. I acidentally pressed the powerbutton on my computer, and when i started it and unity again my prefab was saying missing prefab (Dummy). I felt pretty dumb. I tried your fix but i dosent work for me. Did you do something else or do you think you know how to fix it in another way?
     
  6. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Since duplicating it worked as a recovery for me I didn't have to pursue any other options, and it hasn't happened since, sorry.
     
    nnadiwisdom1 likes this.
  7. nnadiwisdom1

    nnadiwisdom1

    Joined:
    Sep 2, 2016
    Posts:
    5
    for anyone who has this problem, this is definitely the solution
     
    cyanspark likes this.
  8. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,472
    Recently I used external SSD again(Sandisk 500g, usb-c connected), similar phenomenon occurs, scene file become 1kb, some script file suddenly become text file and some weird unicode or whatever characters messed around to normal code,

    at this time, scene file recovered by drive recover process of windows 10, for script file, I should copy from old one.

    but it becomes clear that I will never use external ssd again as project file holder.

    so now I am switching it to some cloud file service and make it sync with my HDD.
     
  9. CMDR_DISCO

    CMDR_DISCO

    Joined:
    Feb 10, 2019
    Posts:
    10
    In case this benefits anyone, this worked for me:

    1. Try right click, see if Reimport is greyed out.
      1. If not, use it.
      2. If Reimport is greyed out, CTRL-D to duplicate.
        1. A new copy should appear. For me, the new copy is not corrupted, but the original is still corrupted.
        2. However, right click on the corrupted original now shows Reimport.
    2. Use the Reimport method.
    Don't know if this will work for you but it worked for me.
     
    Gamba04, mocky55, MrKsi and 2 others like this.
  10. unity_7JeWjGdEnmQwIA

    unity_7JeWjGdEnmQwIA

    Joined:
    Jan 24, 2021
    Posts:
    2
    My power went off for a sec and my file got corrupted.
    What I did:
    find the corrupted prefab
    make a bkp of the .prefab file, just in case

    removed the last component entirely and saved.
    If you were lucky that is corrupted just in the end you may recover some work

    EDIT: unity should need to fix this. Modify the buffer. save to bkp and change references. why they do not do that ?!
     
  11. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    I'm sorry you've had this issue. Please consider using proper industrial-grade source control in order to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    Here's how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally setting Unity up (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  12. FrickinSilly

    FrickinSilly

    Joined:
    Feb 19, 2020
    Posts:
    53
    Just to add to this thread, because it happened to me today after Unity crashed during editing a prefab.

    The first thing I did was check my unstaged changes in git and there were NO changes to the prefab that was problematic. git was of no help. I could reimport the prefab, and that would work temporarily, but when I would edit something in the prefab it would un-import.

    I finally fixed it by editing the prefab within another prefab (hard to explain), but that's besides the point. Recovery was unintuitive, and not aided by git. I still don't know what caused the issue.
     
  13. prabeshpathak02

    prabeshpathak02

    Joined:
    Aug 2, 2021
    Posts:
    3
    Please teach me i had same problem today
     
  14. FrickinSilly

    FrickinSilly

    Joined:
    Feb 19, 2020
    Posts:
    53
    ok, so the reason I refrained from answering was because I did not fully understand why what I did worked. It could very likely be an incorrect solution. Now that the caveat's out of the way:

    First, I described my issue backwards. I had a Prefab A and a Prefab B. Prefab A had an instance of Prefab B as a child game object. Anytime I updated something in Prefab B, it would "break" Prefab A and I would have to reimport Prefab A again in the project view. By going into Prefab A and changing something arbitrary and changing it back, it stopped this broken loop.
     
  15. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Some info about Missing script warnings, broken prefabs, GUIDs, renaming GUIDs, etc:

    https://forum.unity.com/threads/problem-with-git-and-missing-scripts.1090876/#post-7024801
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6487297
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6488230

    EVERYTHING in Unity is connected to the above GUID, which is stored ONLY in the metafile.

    It is super-easy to inadvertently change it by renaming outside of Unity. Don't do that. Instead:

    - close Visual Studio (important!)
    - rename the file(s) in Unity
    - in Unity do Assets -> Open C# Project to reopen Visual Studio
    - now rename the actual classes, and MAKE SURE THE FILE NAMES DO NOT CHANGE!

    If you are NOT using source control while you do this, renaming files is an EXTREMELY dangerous process. Use source control at all times so that you can trivially revert if you miss a critical step and damage your project.

    I'll repeat myself again because obviously you're not using source control:

    Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    Here's how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally setting Unity up (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It's simply ridiculous not to back up.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  16. FrickinSilly

    FrickinSilly

    Joined:
    Feb 19, 2020
    Posts:
    53
    I'm not sure why you would make a bold (literally) claim that I'm not using source control when I explicitly said I was using git. There were no unstaged changes, meaning there was nothing to revert to fix the issue (and no, I hadn't made a commit preceding this event). That means the issue was not in the project itself. That was further evident by the fact that I could continually re-import the broken prefab and it would work perfectly. My guess is it was something in the editor. It only occurred after a Unity crash. Again, I used git, and again, there were no unstaged changes after the crash or after the prefab broken.
     
    RambertoEco likes this.
  17. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,606
    Don't think too hard on it, it's just their usual copy paste they throw around everywhere that is directed towards the thread in general and not to you specifically.
     
    FrickinSilly and Kurt-Dekker like this.
  18. emrehtpglu_unity

    emrehtpglu_unity

    Joined:
    Jan 25, 2021
    Posts:
    1
    I had the same problem and all I did was delete the .meta file. Unity created this again and everything resumed where it left off.
     
    Baydogan and SunnyValleyStudio like this.
  19. MaZy

    MaZy

    Joined:
    Jun 29, 2012
    Posts:
    103
    Happen to me just now. I changed values and wanted to override. Suddently unity had forever "importing" window showing up. I was forced to restart the editor. After this the prefab was broken. GG, Well played.
    Lucky I have a script which spawns this prefab as non prefab version to the canvas. So I could drag out and make prefab again.

    Also use git.
     

    Attached Files:

    Kurt-Dekker likes this.
  20. b1gry4n

    b1gry4n

    Joined:
    Sep 11, 2013
    Posts:
    146
    if ctrl-D doesnt work in your project folder, try right clicking your prefab > show in explorer and then copy/paste the .prefab file. refresh in unity and you should get a duplicate
     
  21. mocky55

    mocky55

    Joined:
    Jul 29, 2015
    Posts:
    8
    Oh.. I was panicking but after reimporting it actually works as if nothing happened.... woo thx! ^^
    My Unity was doing one of those loading bar processes it does at random intervals but it stalled for over 10 mins so I force quit it. Then every time I opened the project again it was missing my whole goddamn canvas prefab DAAAHH!!! Glad it's back
     
  22. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Most people not using source control simply lose their entire projects irrevocably. You got extremely lucky.

    Consider this your grace warning to use proper source control.

    See above.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  23. vignesh_unity837

    vignesh_unity837

    Joined:
    Jun 1, 2022
    Posts:
    1
    I frequently had editor crash when I was using RequireComponent(typeof(<MonoBehaviour>)). Removing that fixed the crash and the prefabs got corrupted. Then right clicking on the prefab and clicking reimport fixed it for me.

    The following steps might help to recover the prefab corrupted:
    1.Open the prefab file in text editor (Make sure you had the forceTExtSerialization is ON)
    2.You can find the guid of scripts here m_Script: {fileID: xx, guid: 1223235434234, type: 3}
    3.https://forum.unity.com/threads/how-to-find-object-by-guid-in-project-window.417608/ ( This'll help you find the script by using the guid)
    4.Then if any of your scripts contains RequireComponent, try removing this line and reimport the prefab by clicking on it.