• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by PictonicStudio · Sep 14, 2013 at 11:09 AM · corruptedcorruptdecompile

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++. alt textalt text

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.

help1.jpg (40.0 kB)
help2.jpg (51.9 kB)
Comment
Bunny83
vexe
hitarthdoc1994

People who like this

3 Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jamora · Sep 14, 2013 at 11:26 AM 0
Share

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.

avatar image ArkaneX · Sep 14, 2013 at 11:38 AM 1
Share

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.

avatar image DannyB · Sep 14, 2013 at 11:47 AM 1
Share

git is your friend

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer Wiki

Answer by PictonicStudio · Sep 14, 2013 at 12:12 PM

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.

Comment
Bunny83
LucasMars
tw1st3d
Zaleort
chino01
Gistix
3dpowermax
HRoland
hitarthdoc1994
imaxus
Hsni
Mehrdad995
ericelbracista

People who like this

13 Show 10 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DannyB · Sep 14, 2013 at 12:22 PM 0
Share

You should at least upvote the answer by @ArkaneX who helped you "find" it...

avatar image ArkaneX · Sep 14, 2013 at 12:54 PM 0
Share

@DannyB - thanks :)

avatar image Bunny83 · Sep 14, 2013 at 01:27 PM 0
Share

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.

avatar image ArkaneX · Sep 14, 2013 at 01:47 PM 0
Share

@Bunny83 - thank you for this information!

avatar image PictonicStudio · Sep 14, 2013 at 02:05 PM 0
Share

Yeah I found the answer like 5 minutes after I posted the question. That typically happens :p

Show more comments
avatar image

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.

Comment
DannyB
Jamora
Bunny83
PictonicStudio
vexe
tw1st3d
HRoland
hitarthdoc1994
vlab22
Hsni
soumen
Mehrdad995

People who like this

12 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PictonicStudio · Sep 14, 2013 at 02:10 PM 0
Share

Thank you for this, even though I found the same answer :)

avatar image ArkaneX · Sep 14, 2013 at 02:17 PM 0
Share

I'm glad you were able to recover content of your file :)

avatar image Hsni · Mar 08, 2019 at 07:45 AM 0
Share

For Windows (simplest way):

  1. Open ILSpy.

  2. Browse to Project folder.

  3. In file manager, search managed.

  4. Open it, there you'll find Assembly-CSharp.dll. Double click it.

  5. Now in ILSpy, search for your corrupted script (After you click the assembly in left pane).

  6. Code of the corrupted file will be there in lower pane. Copy and paste it in file that was corrupted in project.

avatar image

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:

  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 :)

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

Comment
aleichert
HRoland
hitarthdoc1994
Snow7L

People who like this

4 Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PictonicStudio · May 07, 2015 at 07:41 PM 0
Share

Cool! nice to know!

avatar image Bunny83 · Jul 28, 2015 at 11:04 AM 1
Share

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.

avatar image aleichert · Apr 06, 2016 at 03:18 PM 0
Share

My 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! :)

avatar image Dave-Carlile aleichert · Apr 06, 2016 at 03:23 PM 0
Share

The other advice given early on still applies. Source Control. Backups.

avatar image aleichert Dave-Carlile · Apr 06, 2016 at 03:57 PM 0
Share

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.

avatar image hitarthdoc1994 · Jun 06, 2016 at 08:03 AM 0
Share

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.

avatar image

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. :-)

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Corrupted lightmap 1 Answer

Unity scene completely broken. How to recover? 0 Answers

Corrupted/disarrange 2D Texture after app is built 0 Answers

Character Motor Script Corrupted 1 Answer

Players can decompile my game and find out the login and password to my sql server.... WHAT DO I DO?? 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges