Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity deleted all cs files open in Visual Studio after computer crash

Discussion in 'Editor & General Support' started by JaggedRenn, Oct 6, 2020.

  1. JaggedRenn

    JaggedRenn

    Joined:
    Jul 30, 2018
    Posts:
    5
    I had a project open and had probably 15-20 files open in Visual Studio. Went to bed and found my laptop had crashed the next morning and rebooted. Opened up Unity Hub, and all the files in VS are now gone. Strangely enough it doesn't even recognize the TMPro namespace anymore either...

    Anyone ever seen this behavior before?
     
  2. DiegoDePalacio

    DiegoDePalacio

    Unity Technologies

    Joined:
    Oct 28, 2009
    Posts:
    506
    Hi @JaggedRenn,

    This is weird... Are you using some version control system like Git?

    If so, you can go to a previous state of your project when the files are still there.


    I hope you can recover your work.
     
  3. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,464
    I've seen changes that Visual Studio said were saved (i.e. CTRL+S and the star goes away) not actually having been saved when I opened the file again later. I've seen saving files in VS not cause Unity to react to them being saved when ALT+TAB back - which I assumed meant they hadn't actually been saved again (prompting CTRL+A,C then V into another file before restarting my system). Either way, both issues felt like VS bugs ..and scary ones at that.
     
  4. JaggedRenn

    JaggedRenn

    Joined:
    Jul 30, 2018
    Posts:
    5
    I do have a backup, but it is a few weeks old. So I can get close to where I was, but not right. Either way, as soon as I get back up and running again I'm going to setup Git for sure. Hate having to recreate.
     
  5. JaggedRenn

    JaggedRenn

    Joined:
    Jul 30, 2018
    Posts:
    5
    As near as I can tell, any of the scripts that I had open in VS are the files that got deleted. Other files with similar purposes are still there. If this is a VS bug, it is super scary for sure.
     
  6. JaggedRenn

    JaggedRenn

    Joined:
    Jul 30, 2018
    Posts:
    5
    The more I look into this, the worse it gets. I'm missing 90% of my sprites in Unity, and overall about 66% of my project. This is really bad :(

    No idea what happened, but I know all these files were there and working a few days ago.
     
    Last edited: Oct 6, 2020
  7. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,037
    Maybe you have an antivirus that quarantined the files? If is set on auto it will get any file on the system and put it in quarantine or worse, delete automatically.
     
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,541
    • Did) you look into actual folder and check for asset files? Are these there? Or physically missing? Don't check via Unity.
    • Check also OS bin.
    • What is your project directory location and what is your Unity installation location.
    • What is your storage avqilable space.
    • You seems do not use any repository, as asked earlier, if you do. I suggest do it primaryly and learn ASAP, how to use it. Check github and github desktop for example.
    • If your laptop crashed, you may have potentially different issues. Even disk failure. You should make secondary drive/online backups of your projects and documents.
     
    DiegoDePalacio and Joe-Censored like this.
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Open files missing after a computer crash would having me assuming filesystem corruption caused by the crash until proven otherwise, regardless of the application involved. First step would be to scan your filesystem for said corruption.
     
    Antypodish likes this.
  10. JaggedRenn

    JaggedRenn

    Joined:
    Jul 30, 2018
    Posts:
    5
    Any advice on a good file system scanner for this type of corruption?
     
  11. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Windows has that built in, just need to tell it to check the disk. Don't know what Mac has.
     
  12. algorithmicvertex

    algorithmicvertex

    Joined:
    May 22, 2016
    Posts:
    8
    This is insane! Just happened to me as well. Closed the project, re-opened it, it somehow reverted or created a blank HDRP template. This happened in Unity 2021.3.2f1. Files are stored on a dedicated partition. There seems to have been a hub update in progress or something, but somehow it triggered the creation of a blank template - despite the project already existing.

    No file or disk corruption. No fancy VCS, just unity and rider.
     
  13. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Lost progress / project / work / stuff disappeared in Unity.

    This article is to help you when you have lost significant progress or work in your Unity project.

    It is designed to give you avenues of discovery and investigation.

    It is NOT a guarantee of restoring your lost work. It is NOT a substitute for proper IT / Data security procedures.

    To decide which parts are applicable to you, look for major bolded headings.

    EVERYTHING IS GONE, YOU CANNOT OPEN THE PROJECT

    Your project probably is still on your computer. Try a computer-wide search for some unique filenames that you know are in the project you think is gone.

    To start your search, one common file to all Unity projects is named
    ProjectSettings.asset


    Some things that might have happened:

    - you are not opening the project that you think you are

    - you are in the correct project but not opening the same scene you had open before

    - you dragged the project (or part of it) into the trash (intentionally or inadvertently)

    - you moved the project (or part of it) somewhere else (intentionally or inadvertently)

    - an overly-aggressive antivirus solution quarantined it because it saw code being compiled in there

    - you're using a directory sync like OneDrive or Dropbox... NEVER USE THESE SERVICES WITH UNITY!

    - something else??

    As I said, it's probably still all on your system to be found if you look in the right places.

    A typical Unity project will have at a minimum the following folders:

    Assets\
    ProjectSettings\
    Packages\


    EVERYTHING IS PRESENT BUT MY SCENE WINDOW IS BLANK

    Close Unity and make a full project backup RIGHT NOW. Do not do ANYTHING else until you back it up 100%.

    Ideally copy that backup to another computer, or back it up into the cloud. This is just basic data processing best practices.

    If you can see all the files and folders of your project, make sure you are opening the scene file you were working in.

    Once you have opened the scene, look in the hierarchy window, select an object and move the mouse over the Scene window and press F to focus that object.

    Additional notes:

    - ALWAYS use proper industrial grade source control (see below)
    - NEVER use Dropbox or any file sync mechanism in Unity.
    - NEVER move files within your project, except by doing it within Unity
    - ALWAYS be sure you are fully backed up before upgrading Unity

    SCRIPTS OR ASSETS ARE MISSING OR BLANK

    Some info about Missing script warnings, 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'm sorry you've had this issue. 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
     
  14. algorithmicvertex

    algorithmicvertex

    Joined:
    May 22, 2016
    Posts:
    8
    Thanks for this. Fortunately Rider IDE has a "local history" option and I reverted everything back. Obviously using GIT, but that shouldn't be a workaround unity's one of many bugs.