Search Unity

Did I just lose a chunk of code due to a VisualStudio and Unity integration bug?

Discussion in 'Scripting' started by ebasoufeliz, Sep 15, 2020.

  1. ebasoufeliz

    ebasoufeliz

    Joined:
    Oct 14, 2019
    Posts:
    1
    Hi all, thank you for taking a look. I'd like to point out I am a beginner and am just doing a small project, so I might not get most of the advanced concepts out there.

    I just want to know if there is any way of finding a backup or some temporary old script file.
    This is what happened:


    For the last hours I have been writing some code in my unity's projects scripts. I have been saving it constantly, but I might not have saved it into unity's scenes for some time (since I had no need to keep coming back to unity). When I decided to test it, I saved and tried playing the scene to test my code.

    It wouldn't run properly: It would give me a Debug.Log message that there was no longer at the script. Also, it would stop there and not do anything I had written in the past hours. At some point, Visual studio crashed and I couldn't do ANYTHING with the windows, saying it was deemed to be ignored or something. I simply forced-closed it and reopened Unity.

    When I reopened the script, I realized I had lost most of my code. When I checked, the line of the Debug.Log that I had erased before was there, what makes me believe that Unity simply rolled back my scripts and did some overwrite on them.

    Now, I have been loking at a lot of suggested temporary and backup files for Visual Studio on the internet, even Unity, but I can't find ANY temporary/backup files (neither this project nor other projects). This makes me assume I have simply lost it and gotta redo my work.

    Is it a normal thing to happen? Can I prevent or even fix it?

    Thank you for your help.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Data does get lost. I wouldn't consider it "normal" but it certainly can be expected.

    It does seem unlikely that visual studio would destroy the files if they had ever been written to disk. I mean maybe, but not likely. Look around in your trash can or perhaps in other folders within your project, your code might still be there.

    You can certainly mitigate against project damage of all kinds (intentional and otherwise) by using source control and committing your work frequently. There's plenty of tutorials to set up git with Unity, and it is free. You can even mitigate against complete computer meltdown by pushing your repository to another computer, a thumb drive, or to a free git hosting service in the cloud like github, bitbucket or gitlab.

    As far as fixing this instance of it, there may be deleted-file recovery tools you can use but who knows if they would prove useful.
     
    Yoreki likes this.