- Home /
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.
If it's corrupted and you don't have a backup. It's gone...
I prefer to have lots of small(ish) scripts, not only in case something like this happens, but also because I like to have a specific role or responsibility in one script. Often times, one responsibility doesn't take that many lines of code. I find it also makes my code more readable.
What do you mean by 'I don't think my file has that'? Either you have source control set up or not. And I suspect if you had, then the file should be committed at least a few times, if you describe it as huge.
If you don't have version controlled project, then I strongly suggest doing it to prevent such problems in the future.
Answer by PictonicStudio · Sep 14, 2013 at 12:12 PM
So I found the answer. And I hope I help someone on their quest.
You need to download this software http://ilspy.net/ (click download binary)
Once installed and opened click File->Open
Navigate to MyBuildFolder/MyBuild_Data/Managed and open Assembly-CSharp.dll and Assembly-UnityScript.dll
Click the search icon on the top and search for your script name. And viola it should be there.
Hope that helped, peace.
You should at least upvote the answer by @ArkaneX who helped you "find" it...
Actually he posted his own answer at 11:19 and ArkaneX at 11:59. His answer was stuck in the moderation queue. Anyways both answers are correct, so don't forget to simply upvote correct answers / good questions.
Yeah I found the answer like 5 $$anonymous$$utes after I posted the question. That typically happens :p
Answer by ArkaneX · Sep 14, 2013 at 11:59 AM
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.
Thank you for this, even though I found the same answer :)
I'm glad you were able to recover content of your file :)
For Windows (simplest way):
Open ILSpy.
Browse to Project folder.
In file manager, search managed.
Open it, there you'll find Assembly-CSharp.dll. Double click it.
Now in ILSpy, search for your corrupted script (After you click the assembly in left pane).
Code of the corrupted file will be there in lower pane. Copy and paste it in file that was corrupted in project.
Answer by moghazy · Apr 06, 2014 at 01:07 PM
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:
Download this software **http://ilspy.net/** (click download binary)
Once installed and opened click File->Open
Open Assembly-CSharp.dll on the root folder of your project.
Congrats! your scripts is here now :)
I just faced this issue and i hope if it will help you too.
Actually i can't remember that the assemblies are compiled into the project root. In all my projects (even the old ones) the assemblies that the editor creates internally are inside the library folder at:
*PROJECTROOT*\Library\ScriptAssemblies\
I literally searched my harddrives for "Assembly-CSharp.dll" and only fould then in build folders or in the "ScriptAssemblies" folder.
I have found about 200 assemblies ^^. I probably should clean up my harddrives but usually when i run out of space i just buy a new one. One day i'll run out of drive letters i guess.
$$anonymous$$y god! The main script of my project on which everything was dependent on had gotten corrupted after my laptop crashed while saving. If it weren't for you I'd have to go through ages of coding again. Thank you! :)
The other advice given early on still applies. Source Control. Backups.
I make several backups regularly and I was just about to make one again after having finished that giant script, but then it crashed. I will look into the version control, sounds like it's a good thing to have.
Don't Recompile/Re - import the Script else You would not be able to Get back the File. That is what I did and I had to write the whole Script Again.
Answer by Xeonce · Jun 22, 2016 at 05:59 AM
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. :-)
Your answer
Follow this Question
Related Questions
Corrupted/disarrange 2D Texture after app is built 0 Answers
Character Motor Script Corrupted 1 Answer
Corrupted lightmap 1 Answer
Unity scene completely broken. How to recover? 0 Answers
Localizing level0 file 1 Answer