All assets deleted / project reset when launched through UnityHub

I read through the threads on this already, and I think this warrants some investigation:

I’m using Unity 2021.1.16f1 with Visual Studio Integration 2.0.11, Visual Studio 2021 Preview, Unity Hub 2.4.5. A couple of things first:

  1. I CTRL-S constantly
  2. I ensured I had no dirty windows before closing Unity
  3. I closed Visual Studio before closing Unity
  4. No source control was active on the project or any child folder

I tried to attach to Unity to debug a script. I got a dialog box saying “Unspecified Error” and was unable to debug. I tried several times, saving, closing Visual Studio and re-launching, but no luck. I had other things to get to.

In this order:

  1. I closed Visual Studio. When I shut down Visual Studio, I ensured that all my windows were clean - all changes were committed to disk

  2. I manually saved the scene in Unity and closed the editor without any warnings

Some time passed. I re-opened my project through Unity Hub (as usual). The project opened as if I had just started a new project from Unity Hub.

  1. All assets I had created including scripts and prefabs were deleted
  2. All package changes I had made (imports, updates) had been reverted
  3. The /_Temp folder in my project was cleared

Interestingly, the .csproj file I had generated when working in Visual Studio was still present. Opening the project file directly in Visual Studio clearly shows what the contents should be, but Visual Studio reports that the files are no longer present.

This affected both files that were open in either editor, as well as files that were not:

To be clear, this appears to be a scorched-earth overwrite of the entire project folder with a completely clean, new template.

A few observations:

  1. If this was a file-handle / lock issue, it would only affect open files. Since this is not the case, I believe this explanation is out.

  2. The package manifest.json file was overwritten. Of particular interest, all added packages were removed, and the specific upgrade of “com.unity.ide.visualstudio”: “2.0.9” to “com.unity.ide.visualstudio”: “2.0.11” was reverted. Additionally, the packages-lock.json was reverted.

  3. The Assets folder’s Date Created and Date Modified were reverted to both be the exact same date and time I tried to re-open the project. The SampleScene.unity and SampleScene.unity.meta in the Assets/Scene folder had their Date Created set to the same time, but their Data Modified was reverted to 4/17/2020 @4:35 AM.

Based on this, I can draw a couple of conclusions:

  1. This is not a file lock issue: it affected all files in the project, open or not as well as reverting changes to dates and times on folders and files created during project scaffolding

  2. This is not a source control issue: no source control mechanism was in place

  3. Visual Studio was closed before Unity was closed. Since Unity did not report any errors while I was saving my work, I can conclude the Visual Studio was not involved in the project corruption. This is further supported by the fact that artifacts specifically in use by Visual Studio (the .csproj files) are intact and in the correct state.

  4. This was not a result of a reported error in Unity3D. Shutdown was clean and reported no errors. Attempting to save a locked file would result in a lock violation in Windows. A search in Event Viewer for any errors related to the Unity3D app yields no results.

Given the above, I strongly suspect that there is an issue in the Unity Hub project launcher that resulted in my project being re-created. Any files or folders present in the template are cleanly overwritten including OS files system metadata. This did not result in my .csproj files being overwritten because those files are only touched when Unity is configured to generate them, and you either click the ‘regenerate’ button, or shell out to Visual Studio to edit a script. They would not be present when being copied from the template.

I’m happy to provide any additional information I can. Hopefully someone will be able to use this to locate this bug.

I did notice that my time zone on my system updated today. I don’t know if that would be significant or not. Good luck bug hunting!

Jules

7423133–908480–manifest.zip (1.39 KB)
7423133–908483–SampleScene.zip (2.44 KB)

3 Likes

First thing I would look for is an overly-aggressive antivirus solution quarantining the entire directory because it saw some DLLs being written there when Unity compiled your scripts.

This is likely the root of your problem. I’m sorry you’ve had this issue. Please consider using proper industrial-grade 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.).

As far as configuring Unity to play nice with git, keep this in mind:

https://discussions.unity.com/t/736093/3

Here’s how I use git in one of my games, Jetpack Kurt:

https://discussions.unity.com/t/807568/3

Using fine-grained source control as you work to refine your engineering:

https://discussions.unity.com/t/826718/2

Share/Sharing source code between projects:

https://discussions.unity.com/t/719810/2

Setting up an appropriate .gitignore file for Unity3D:

https://discussions.unity.com/t/834885/5

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.

“Use source control or you will be really sad sooner or later.” - StarManta on the Unity3D forum boards

1 Like

Thanks for the reply - however this was more of a bug report than a cry for help. I definitely agree: anyone finding this thread, turn on source control. It will provide (some) protection against this!

On another similar thread, a reply suggested that a faulty source control may have been the issue. The presence or absence of a .git folder should not affect whether one of the Unity runtimes nukes a project on startup. I think it’s a relevant observation that this happens with or without source control. Since I happened to observe the behavior before I turned on source control, my report helps to eliminate a possible cause: source control.

In short, yes, I agree that using source control and pushing to a remote regularly is best practice. However, somewhere lurking here is a really evil bug, and using source control to guard against it is a work-around. The root of this is that something in the behavior of part of the project system sometimes results in the overwrite/deletion(?) of files in the project folder. It’s fortunate that the .git folder seems to be spared, but depending on where you are in a stage/commit/push/pull/merge cycle when your project gets nuked, you can still end up with a broken local repo.

I’ve been trying to repro this a little without much luck. I did successfully get it to happen once by:

  1. Opening Unity Hub
  2. Creating a new project and launching it (Unity Hub automatically minimizes)
  3. Close and re-open Unity Hub while the project was loading
  4. Making some edits
  5. Saving my edits
  6. Closing Unity
  7. Opening the project from the newly running instance of Unity Hub
  8. Observed complete reset of project (folders not originally set up by Unity remain intact, including .git)

I was doing a git init during my attempts to reproduce; on this run I turned it on after step 5 and committed.

One observation here is that while git observed this as a change, resetting to HEAD would still result in losing anything not yet committed. This includes changes to the package manifest.

Unfortunately, the above only worked once for me: two subsequent attempts did not reproduce the issue. My suspicion is that it has something to do with Unity Hub incorrectly determining the state of a project, and scaffolding a new project over the existing one. I don’t know what’s happening under the hood, so it could have a lot to do with the timing of the actions I listed. Variability in when I get my clicks in, system resources and load might be heavily affecting reproducibility as well. When I have time, my next idea is to substitute step 3 with initiating a Unity Hub update. If do successfully dial in steps to reproduce reliably, I’ll post them here.

For now, all I have is a suspicion.

Based on my observations so far, you should be able to successfully mitigate this by ensuring you commit and push before you re-launch your project. This is a little counter-intuitive, since we’re generally used to committing and pushing after we save changes we’re happy/done with.

If you close your project, the editor crashes, or you close and do something else (like work in VS, Blender, etc.) and want to come back to it, be aware that it’s the files in the project folder not committed before launch that are potentially exposed. Once you click the project launch button, if the dragon happens to be there, it’s too late.

Yeah. Appears to be an issue. I just encountered this as well. Everything wiped back to a previous state after restart from Unity Hub.

To an amateur playing with Unity just for fun, without version control, this could be traumatizing. Or even if you’re just prototyping a bit before setting up a proper project. Many situations where you won’t have VCS set up yet and lose a bunch of work for no good reason.

What seems crazy is the Assets are wiped from disk. Not just Unity’s view of the project structure. Some task on startup has the authority to completely scorch earth the Assets folder. This should never be allowed without taking some kind of backup first. Way too dangerous.

2 Likes

What on earth!? This just happened to me while prototyping for a project. An entire day’s work is gone now and I’m feeling extremely paranoid. Setting up source control for every one-day-prototype during a rapid ideation phase creates a lot of overhead so I’d like to avoid this.

Also, I don’t feel like I should have to put up safeguards against the engine I’m using deleting the entire project.

3 Likes

I just encountered this too. Early prototyping phase and no source control off course
unfortunately, I stored some models exclusively in that project.

I just encountered this, first time ever after years of using different Unity versions. Happened when launching Unity 2020.3 – thankfully a full backup archive (with all assets as textures etc etc) and a checkin to versioncontrol with all meta-data, scripts etc saved me, because I almost shit my pants…

Edit: Should mention that I just restored all data to disk, and now launching the project again and it is doing a lot of processing to ‘import’ all assets, so not 100% there yet that everything works incase Unity messed up some local file and tries to recover by itself by resetting all to blank project… if it does, I need to start over and manually introduce all files again…ufffgh…

I can confirm, this has just happened to me as well, Unity completely nuked my prototype, I was only ~4-5 hours in, but still sucks. Recovered most files with Recuva, but that’s no good, too many are corrupted, gonna have to start fresh. The logs don’t mention any delete.
This is definitely a bad bug, there have been reports of this ever since 2014, which unity chose to ignore.

This just happened to me. See you later weekend prototype… The one time I didn’t immediately set up source control as well.

My recollection of events:

  1. New 2021.2.8f1 Unity project from 3.0.1 Unity Hub.
  2. Worked on and off the project without ever restarting Unity for a few days.
  3. Tried to do a build but got this error:

Read that a simple restart of Unity will fix the problem.
4. Save everything, Close Unity.
5. Launch project again from Unity Hub.
6. Build.
7. Open apk and sees the default table saw scene on my phone…
8. Check project and find everything nuked.

This also happened to me yesterday :frowning:

Recollection of events:

1.) New project, work on it for 2 weeks. (Unity is perma open)
2) Hit build and run, and it runs ok
3) Back in unity, hit play, and for some reason, all the Sprite Layer orders are wonky. ( I theorise now, they are all set back to 0 and any changes are lost)
4) Correct them all and hit save. Try to close or switch the scene, but it wont close. (At this stage, I can still hit play no problem!)
6) Try to save as the scene so I have 2 copies, but it wont save. (the window closes, but no file is made)
7) Think thats weird, close unity and reopen.
8) I have a fresh project, with just one asset, that I had added and then deleted from the project, about 2 days ago. All other(100 or so assets, scenes, animations, created both before and after this rejected asset), are gone.

  1. Setup source control, on next project :slight_smile:

Follow Up:

I had OBS left recording for a couple of days and it had made a 2.4TB mkv file, before filling the HDD up that was shared with my project, so I imagine it ran out of space and unity got nuked.

Just had a prototype get nuked as well. Not even a recovery porgram is finding the data.
This is one scary bug…

Your project is almost certainly NOT “nuked.” Some things that might have happened:

  • you are not opening the project you think you are

  • you are not opening the same scene you had open before

  • you dragged the project into the trash (intentionally or inadvertently)

  • you moved the project 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… DO NOT USE THIS WITH UNITY!

  • something else??

Whatever the result is, it’s probably still all on your system to be found. Search for some filenames you know are in the project you think is gone.

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://discussions.unity.com/t/736093/3

Here’s how I use git in one of my games, Jetpack Kurt:

https://discussions.unity.com/t/807568/3

Using fine-grained source control as you work to refine your engineering:

https://discussions.unity.com/t/826718/2

Share/Sharing source code between projects:

https://discussions.unity.com/t/719810/2

Setting up an appropriate .gitignore file for Unity3D:

https://discussions.unity.com/t/834885/5

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.

“Use source control or you will be really sad sooner or later.” - StarManta on the Unity3D forum boards

Happened to me. I was done working on a prototype; went to close out VS/Unity & check into git. Found out I had a missing item and needed to do a rebuild, opened Unity back up and everything is gone. Library still has artifacts of build, but everything in Assets is nuked.

Just had the same thing happen to me. The project is very much nuked. I’m using Unity Hub 3.1.1 on Linux. Fortunately, I only spent a few hours on it

Reviewing the the editor log, the following line is part of the “COMMAND LINE ARGUMENTS” list:

-cloneFromTemplate
/home/user/Unity/Hub/Editor/2021.3.1f1/Editor/Data/Resources/PackageManager/ProjectTemplates/com.unity.template.3d-8.1.0.tgz

Did it just re-clone the template over my existing project? I opened the project directly from the hub’s project list

Edit: This just happened to me again (about a year later) when using Unity Hub 2.4.5 so it’s not an issue with Hub 3.0 as I thought. The project was wiped after I signed back into my account and opened the project through the Hub. I had the project open moments earlier trying to build but received an error about my account’s authorization/permission not being valid.

Have had this happen three times previous times had git repo just restored project.
Steps i did to have this happen to me.

  1. Installed new unity version 2022.2.0a13
  2. downloaded 3D(URP) template and created new project “ProjectA”
  3. Imported some models and animations
  4. Wanted to open other project to compare some settings unity hub was complaining that “ProjectA” is already open i made sure i am opening different project.
  5. closed opened project and it reset itself.
  6. afterwards i am able to open both prjects fine but “PrjectA” is just empty files were not in recyclebin.

+1 for happened to me. Absolutely everything is nuked and honestly I can’t really believe my eyes. I’ve never seen or heard of a software that is work related for most of us absolutely nuke the project folder. It’s shocking. I think the engine itself has been around for years but the hub that’s tacked on seems to be the culprit

“oohh use source control”. I do, but I commit at the end of the day or every few hours. Losing hours of work is annoying af. Using a mac which from the looks of the folder paths seems to be the common trend here.

My timeline:
Hit an infinite loop in the editor script. Force quit unity and I can’t quite remember how I tried to launch it again, might have been the hub. Boom everything nuked and visual studio helpfully went back to the last git version it had.

Not sure if it is relevant but I did also a see a ‘project X is already open’ as well compared to ^

1 Like

This just happened to me too… Just did a fresh prototype for two hours, nothing major but a pain to lose when you are on the clock.

V 2021.2.7.f1
URP

Saved many times, imported assets, created folders, changed settings etc.

Unity crashed, I restarted the project via Hub and it was fresh as the minute it was created…

The relevant SSD had 25GB left, which this project was not.

Don’t think GIT would have helped here because Unity is just not saving anything in the first place. Everything must have been in temp and wiped when I restarted the project…

RIP.

same issue, had a prototype project open for 2 weeks was noticing slowness in loading assembly, saved everything and restarted the project , it took a long time to load and was performing some sort of copy, I let it run overnight, then the next day, everything was gone back to a sample scene, hundreds of scripts and assets were removed without a trace

yup, just lost my entire project I spent 8 hours on. Thanks a lot unity, this was my first game, and I was just about to test it out on my phone. I created an entire game and EVERYTHING is gone…

Just ran into this issue. Source control doesn’t help when you’re still testing out changes that you’re not ready to commit.

Not a good look.

2 Likes