Unity crashed and corrupted a huge .cs script.

The problem: I have a corrupted script that shows up blank in MonoDevelop, and a bunch of nulls in Notepad++.

What I have tried: I’ve tried version history, but I don’t think my file has that. I’ve searched for how to de-compile a unity project (I have a recent build) to retrieve my script, but none of that has worked yet.

So I found the answer. And I hope I help someone on their quest.

  1. You need to download this software
    http://ilspy.net/ (click download
    binary)
  2. Once installed and opened
    click File->Open
  3. Navigate to
    MyBuildFolder/MyBuild_Data/Managed
    and open Assembly-CSharp.dll and
    Assembly-UnityScript.dll
  4. Click the search icon on the top and
    search for your script name. And
    viola it should be there.

Hope that helped, peace.

If you have a recent build, then you can decompile it. Here’s a short info how to do it on Windows.

After building a project, you have an exe file, let’s name it MyGame.exe, and folder MyGame_Data. Inside this folder there’s subfolder Managed, containing the compiled Unity assemblies. Those interesting you are:

C#: Assembly-CSharp.dll, Assembly-CSharp-firstpass.dll

JS: Assembly-UnityScript.dll, Assembly-UnityScript-firstpass.dll

Your code is most probably inside an assembly without firstpass in its name.

To decompile, download any .NET decompiler. I suggest free ILSpy or trial version of .NET Reflector. After opening decompiler, drag the assembly and just browse to desired file. If your class was contained within namespace, then it will be accessible under this namespace. In other case, it should be under empty namespace (minus sign). Clicking the class should open it in disassembled form, though if I remember, in .NET Reflector you have to double click it or right click and select Disassemble.

If you have a corrupted scripts only and you don’t have a building project this is the solution which is similar to PictonicStudio solution:

  1. Download this software http://ilspy.net/ (click download binary)

  2. Once installed and opened click File->Open

  3. Open Assembly-CSharp.dll on the root folder of your project.

  4. Congrats! your scripts is here now :slight_smile:

I just faced this issue and i hope if it will help you too.

Big, big Thanks to you!!

You have saved me from over 30 hours of work, cause i have deleted all
my original scripts by mistake, without backup, and on a ssd…

I have tried a backup tool, but this also has failed.

Without you i were not so happy in this moment as i am now. :slight_smile: