Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved Missing prefabs and components after cloning fresh from GitLab

Discussion in 'Editor & General Support' started by Skelbo, Dec 23, 2021.

  1. Skelbo

    Skelbo

    Joined:
    Dec 28, 2020
    Posts:
    38
    I'm getting critical errors and I have a project due very soon, so it's an urgent request for help, if anyone has any knowledge on this. I can't simply submit a bug report since that may take many months to fix.

    I looked around the forum and known issues but can't find this anywhere. Basically, my project worked fine until today. When I opened it up I got a bunch of missing prefabs and component references (showing red in scene). I had not changed any paths, didn't move any prefabs or folders around. In fact, I had just cloned the repository from GitLab. I checked the folders where I stored all my prefabs and they were all there. I checked the folders where all my sprites, scripts and other assets that unity claimed missing were and they were there too. So I don't get how they're missing even when I can see them right there in the folder where they've always been.
    When I selected one of those prefabs though, it had missing component references such as scripts and sprites. Example:

    Unity error prefab.jpg
    Here the transform, rigidbody and colliders are kept but the scripts and all sprites are missing. Although the sprite or script locations have not changed.

    Example screenshot of all errors:

    Unity error.jpg

    Some extra context: yesterday I had issues with Unity being very slow and crashing due to limited HDD space on my device. I had 20 GB free space when I started working and a few hours later it all filled up and I couldn't even save some script changes. The reason for this also eludes me, since I did not add any new assets in those hours. I have no idea how 20 GBs can disappear into thin air while just working in the editor.
    The device I am using is not ideal but I have no choice. I cleared up as much space as I could but it still wasn't enough. So I copied the project to an external HDD and tried to run it from there instead. I deleted the project from local drive (it was around 50 GB).

    Trying to run the editor from external HDD was extremely slow. Any change I made took 30 seconds or more to apply. Even just changing some position or name of an object. Then Unity crashed again.

    So today I decided to try running the project from local drive again, starting with a fresh clone of the repository. Then this happened.

    What I tried so far:
    • Reimported all assets.
    • Reverted any changes done in the past 2 days from github client.
    • Opened the project in other Unity versions (I use 2021.2.6f1. I tried updating to the latest version 2021.2.7f1 and opening in 2020.3.24f1).
    • Removed the project and copy pasted the external HDD backup folder on local drive.

    None of these worked. I can't seem to narrow down what the problem is.

    Since it's not just one or 2 prefabs missing, I can't possibly manually replace every single asset and reference. It's a rather large project. I'm borderline having a panic attack just thinking about a whole year's worth of work going down the drain with a deadline approaching in a couple weeks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,309
    Did you properly source control 100% of your metafiles along with the project? That's not optional, and failing to do so will result in precisely the behaviour above.

    Running out of hard drive space is another "all warranties are void" situation.

    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. 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.
     
    ycode and bugfinders like this.
  3. Skelbo

    Skelbo

    Joined:
    Dec 28, 2020
    Posts:
    38
    Yes. After I make any local changes to the project I push all commits to repository. I've never had a problem with this until today. I haven't moved or deleted or even renamed any files before this happened.
    I never manually move project files around in explorer (anymore). I do it inside unity project view ever since last year when I experienced a sync problem when I moved files outside the editor and they weren't recognised inside.

    I'm confused about the guid. Am I supposed to change the guid of each prefab with an older one? Which guid am I supposed to change to? It's not like there's different versions of the prefabs. I haven't deleted or moved any so how do I know what to change it to?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,309
    You shouldn't have to change GUIDs ever, or really even be aware of them. The fact that it's not finding them would point to the meta files not being properly source controlled, but I'll take your word that they were.

    I suppose the next step would be to pick one missing script, ideally a script that is used in only one place.

    Study that place it is used (prefab or scene) and identify what GUID that place is trying to use that is missing, and compare it to the GUID that is currently in the metafile for that script.

    You can use a find-in-files to see where that GUID is in the project, if any place. This can give you clues about where things went wrong. Most likely the solution will be something trivial, but you have to figure it out and GUID-hunting like the above could give clues.

    Alternately you can also go back in time in your repo commits until it does work.

    Also, if you ever duplicate stuff in Unity, this will also generate fresh GUIDs for the copy, and then if you deleted the original and kept the duplicate, everything would be disconnected.
     
  5. Skelbo

    Skelbo

    Joined:
    Dec 28, 2020
    Posts:
    38
    I searched for the missing GUIDs on my local device and I couldn't find any .prefab.meta matches but I found matches in Library/metadata. Each search gave 2 files: 1 with no type and 1 of .info type.

    Example:
    GUID hunting result 1.jpg

    I tried searching for GUIDs of prefabs I only used in 1 scene and also for prefabs I used in multiple scenes, such as the player. Both returned same type of results.

    I tried searching the GUIDs in my Git repository as well and I found code references for those missing GUIDs, dating back to as recent as 1 day ago (when I already had this problem). The same missing GUID was shown referenced in code from 2 days ago, 3 days ago, 1 week ago etc.

    Example:
    GUID hunting result 2.jpg

    So I'm still lost. I don't get how it's missing if it is referenced even on the day I started having this issue. I reverted the commits from 2 days ago even, and I'm getting the same thing.

    I noticed something though, in my .gitignore file I have *.meta there. Does that mean git is set to automatically not commit any .meta files? How can that be? I never messed with the .gitignore file, I left it as it was when it got created. Never had problems with missing prefabs before. If this means my .meta files were never copied over on repository, then how come I've never had missing sprites and components until now? Wouldn't it have given me errors like this since day one?

    Screenshot of .gitignore:
    Gitignore.jpg
     
  6. Skelbo

    Skelbo

    Joined:
    Dec 28, 2020
    Posts:
    38
    Update: I found another backup on external HDD that had the right version and everything is thankfully ok again.

    I modified .gitignore to not ignore .meta files now. I pushed the commit and I can see all the meta files in my repository now. Is there any other type of file I should remove from .gitignore to avoid getting this kind of errors (or worse) in the future? I really hope I don't have to go through something like this again.
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,309
    Oh yeah, that's bad!

    YEAH! You lucked you there Skel... yes you dodged a very nasty bullet here.

    Pretty much every file under the directories:

    Assets
    ProjectSettings
    Packages

    MUST be committed. This includes .meta, and also things like DLL and .a, which some pre-made .gitignore files ignore. If you ever get a .gitignore somewhere, make sure it's made for Unity, not for some other environment.

    I also check if the Project Settings -> Editor is set to Force Text for asset serialization, since that makes finding differences much easier. It's the default nowadays.
     
  8. Skelbo

    Skelbo

    Joined:
    Dec 28, 2020
    Posts:
    38
    Thank you very much for the advice!
    I've encountered yet another problem now preventing me from even opening my project but I'll start another thread for it since I'm not sure if it's related to my original problem or not.
    But just for reference, I'm getting Locked Library/ArtifactDB file error.
     
  9. Arganoid

    Arganoid

    Joined:
    Oct 12, 2013
    Posts:
    24
    I just had the same problem, it seems that the default Visual Studio .gitignore file excludes *.meta.
     
  10. bruceb85

    bruceb85

    Joined:
    Sep 26, 2020
    Posts:
    45
    I have this same issue after trying to access a unity project from a different computer. The unity folder is in iCloud Drive. No changes have been made, all the .meta files appear to exist unchanged. So not sure why opening the project all prefabs are missing. How can I resolve this?
     
  11. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,309
    Drive mirroring services are explicitly not supported by Unity.

    Use source control.

    PROPERLY CONFIGURING AND USING ENTERPRISE SOURCE CONTROL

    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

    I usually make a separate repository for each game, but I have some repositories with a bunch of smaller test games.

    Here is 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 the ONLY folders you should ever source control are:

    Assets/
    ProjectSettings/
    Packages/

    NEVER source control Library/ or Temp/ or Logs/
    NEVER source control anything from Visual Studio (.vs, .csproj, none of that noise)

    Setting git up with Unity (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.

    If you plan on joining the software industry, you will be required and expected to know how to use source control.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  12. bruceb85

    bruceb85

    Joined:
    Sep 26, 2020
    Posts:
    45
    Ok but how do you push to git if the unity projects are too large, I previously tried but couldn't figure out how to get around it using git desktop.
     
  13. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,158

    well the key trick is to be pushing them from the start. i had a large project that i had imported basically a bucket load of assets into and it was "too big" so what did I do, shut unity, shut everything, move out various folders under windows, till there was 1 under assets, and then commit that, and push, then add the next, commit, push, the next commit push.. till all were there.
     
  14. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,309
    git itself has no file limits. Hosting services like github have total size limits and individual size limits.

    The most common cause of large files is misconfigured ignore files, or trying to commit massive things like movies or long pieces of high quality audio or lightmap bakes, which can be massive.

    It's best practices to use git-lfs for larger files, but not necessary.

    Using git to source control is separate from pushing commits to a remote service.

    You can always commit to git locally, assuming you have enough drive space.

    You can always clone your repo to an external drive (thumb or otherwise) for offsite backup.
     
  15. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,158
    I had issues even with lfs, when i loaded all my textures in :p despite them all being not overly big because the commit gets zipped up it gave up sending it, it didnt complain it was too big, it just gave up which was highly irritating hence i did the directory by directory approach as they were split into various groups
     
    Kurt-Dekker likes this.
  16. bruceb85

    bruceb85

    Joined:
    Sep 26, 2020
    Posts:
    45
    so how am i supposed to know what file extension to use with LFS? Git desktop personal has a 100mb limit, if you exceed the limit you can no longer push to the repo.
     
  17. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,158
    well any files >50mb is probably a good place to start, just run a scan and find your big files and keep an eye on them