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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Official Addressing issues with missing references

Discussion in 'Prefabs' started by volblob73, May 15, 2020.

  1. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    29
    We finally have a fix to an elusive issue that we know has caused frustration for many of you for a while. MonoBehaviour-based components as well as ScriptableObjects would lose references to other objects under certain conditions when the scripts they were based on temporarily didn't compile.

    This could for example happen under the following conditions:

    1. A team member fetches updates from version control where a script component has a new field and a Prefab that uses the script has a reference to another object assigned in that field.

    2. However, due to local changes, the updated script doesn’t compile. This means the Prefab cannot import and so the added field is not present on the Prefab.

    3. Once the compile error is fixed, a reimport of the Prefab can make the reference appear again. Unity keeps track of missing imports of Prefabs so it can automatically reimport them once the compile errors have been fixed. However, this information about missing imports is lost if the editor is restarted. In this case, the reimport does not happen automatically after all, and the reference remains missing even though there are no longer any compile errors.
    Usually, the issue could be worked around by reimporting the affected Prefabs or other objects manually. However, tracking down the issue is not always trivial, and is made worse by the fact that it can manifest differently for different people working on the same project. Some of you have resorted to simply reimporting all Prefabs to be safe, which can take a while, especially for large projects.

    A robust Asset dependency-based fix
    The fix required introducing a new form of dependency in the Asset Database. Prefabs and other Assets now have a script type dependency on the MonoBehaviors and ScriptableObjects they contain instances of. Like with other Asset dependencies, this means that if a script type is changed, the Assets that depend on that script are reimported.

    Luckily, it's not simply any edit of a script that causes dependent Assets to be reimported. It only happens if the fields of the script change, meaning fields are added or removed, or existing fields change name, type, or order. Changes to methods or properties won't cause any imports of dependent Assets to happen.

    This change is needed because the imported result of Prefabs and other types that contain MonoBehaviors or ScriptableObjects depend on the fields of those scripts. So when the fields on those scripts change, a reimport must happen for the imported result to reflect those changes to the scripts.

    It’s worth being aware that the new dependency will cause Prefabs to get re-imported upon script changes in cases where it didn’t happen before. This is a necessity of the more robust way of ensuring Prefabs get imported when they need to, in order to avoid missing references.

    Versions of Unity with the fix
    The fix will be coming to Unity 2020.1.0b10. Additionally, we are backporting it to Unity 2019.3, where it should become available in a couple of weeks. Since the fix depends on infrastructure that’s part of AssetDatabase v2 which was introduced in 2019.3, it’s not possible to backport the fix further back than 2019.3.
     
  2. rskorski-wizards

    rskorski-wizards

    Joined:
    Feb 27, 2018
    Posts:
    8
    We are very much looking forward to this fix in 2019.3! You mentioned that it depends on in AssetDatabase v2 infrastructure, does that mean our project will have to upgrade to v2 in order to benefit from the fix?
     
  3. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    29
    Yes, you need to use Asset Database v2 for this fix. Any specific reason why you are using v1?
     
  4. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    29
    Fix will be available in 2019.3.15f1.
     
  5. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,172
    This is great news! Is the fix also on 2019.4 LTS?

    Edit: Yes it is!
     
    Last edited: Jun 12, 2020
  6. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Xarbrough likes this.
  7. KAJed

    KAJed

    Joined:
    Mar 15, 2013
    Posts:
    117
    I have found v2 to still be incredibly unstable and makes my projects unable to import even in some of the most basic circumstances (ie: small project, small number of packages).

    As such I have not been able to recommend moving to v2 for my team.
     
  8. OAT_PICKER

    OAT_PICKER

    Joined:
    Nov 15, 2013
    Posts:
    6
    My team have also found v2 to be unstable, regularly hanging on launching the editor.

    We really need this missing references bug fix, but cannot update to v2 in its current state.
     
    KAJed likes this.
  9. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    29
    @KAJed @OAT_PICKER
    Have you reported the issues you have had? I can then have a look at them. We do have bugs in v2, but generally we are getting good feedback on v2.
     
  10. KAJed

    KAJed

    Joined:
    Mar 15, 2013
    Posts:
    117
    Yes. However, the core issue for me appears to be that triggering another load of any kind from inside an assembly load causes it to hang indefinitely on a mutex lock. I have pretty detailed information that I went over with the bug rep but felt like they misunderstood the problem. I diagnosed the problem with the lead on Odin Inspector since that particular asset was exhibiting the behaviour. The "fix" for it seems rather messy and we both felt like it shouldn't be needed.
     
    sirxeno likes this.
  11. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    29
    @KAJed do you have a case number for that issue?
     
  12. KAJed

    KAJed

    Joined:
    Mar 15, 2013
    Posts:
    117
    My case number for the issue is 1263658. There were unable to reproduce the issue in house but for me it was 100% repro.
     
  13. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    29
    @KAJed your case got marked as a duplicate other another case (1260657). This other case has just been fixed. Fix is available 2020.2 and should be available for 2020.1 and 2019.4 very soon.
     
  14. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    260
    TextusGames, Rodolfo-Rubens and Jes28 like this.
  15. rt_jscott

    rt_jscott

    Joined:
    Jun 20, 2017
    Posts:
    13
    What date and version was the proposed fix for this?
    I am having this problem often as well.
    I am on 2019.4.9f1 but the release notes don't include date and the posts here only include dates.
     
  16. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,192
    I'm having this same problem on 2019.4.17f1... The prefab itself is okay on prefab mode, no missing child-prefabs, but when dropped in the scene they are 'missing prefabs'...
     
  17. deLord

    deLord

    Joined:
    Oct 11, 2014
    Posts:
    306
    Not sure if this is the exact problem mentioned in the OP but I get a NPE in my script
    Code (CSharp):
    1. Destroyer dstr = Instantiate(Resources.Load("Prefabs/Destroyers/myprefab"), sometransform) as Destroyer;
    2. if (dstr.someBool) ...  // dstr null
    but then the object is instantiated correctly in the scene. Using 2019.4.18f1 LTS
     
  18. KAJed

    KAJed

    Joined:
    Mar 15, 2013
    Posts:
    117
    In this case you're getting an error because you're casting directly to a component type. If that is a prefab then you need to GetComponent on it instead.
     
  19. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    242
    Looks like 2020.2.4 has caused a regression in this issue and it is happening again
     
  20. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    424
    @volblob73

    The issue with missing nested prefabs in scene is still here in 2019.4.18 LTS
    (It is possibly happens if not exit from unity before git check out / pull).
     

    Attached Files:

  21. mahdi_jeddi

    mahdi_jeddi

    Joined:
    Jul 18, 2016
    Posts:
    216
    Just upgraded the project from 2020.3.12 to 2021.2.b1 and got missing references in the nested prefab in an object in the scene.
     
  22. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    260
    It's getting even worse. Now also localization string references are affected. This is really, really annoying. My work-around so far is to purge Unity's cache folders (like `Library`) before doing a production build. This typically restores all broken links. But dare you if you forget to do it. It might render your complete app unusable.
     
    M_R_M likes this.
  23. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    424
    We managed to overcome this issue in builds.

    In our build pipeline we call method to reimport all prefabs (at earliest stage).

    Code (CSharp):
    1.         public static void ReimportAssets(string searchFilter)
    2.         {
    3.             var timeBeforeSearching = DateTime.Now;
    4.        
    5.             // Finding assets
    6.             var objectGuids = AssetDatabase.FindAssets(searchFilter);
    7.             var objects = new Object[objectGuids.Length];
    8.             for (var i = 0; i < objectGuids.Length; i++)
    9.             {
    10.                 var objectGuid = objectGuids[i];
    11.                 var objectPath = AssetDatabase.GUIDToAssetPath(objectGuid);
    12.                 var loadedObject = AssetDatabase.LoadAssetAtPath<Object>(objectPath);
    13.                 objects[i] = loadedObject;
    14.             }
    15.        
    16.             // Selecting assets and executing Reimport
    17.             Selection.objects = objects;
    18.             EditorApplication.ExecuteMenuItem("Assets/Reimport");
    19.        
    20.             Debug.Log($"[{searchFilter}] Assets were imported. [{(DateTime.Now - timeBeforeSearching).Duration()}]");
    21.         }
    Code (CSharp):
    1. ReimportAssets("t:Prefab");
    And this code (if you call it before build, (in our case it is called automatically)) solves missing reference problem in builds.

    Clearing Library folder is also valid solution (but it takes much longer time).
     
    Last edited: Jul 23, 2021
  24. D12294

    D12294

    Joined:
    Oct 6, 2020
    Posts:
    71
    Hello everyone,

    I have the same Issue on a cloned project with unity 2021.2.7f1 with following setup: I developed on PC, got a error free compile state, uploaded the project to Azure DevOps, then cloned the project on a Mac in terminal via git clone <clonepath> and after opening the project in unity all sprite references are missing. I really have no idea whats going on. I use the following git ignore file

    Code (CSharp):
    1.     # This .gitignore file should be placed at the root of your Unity project directory
    2.     #
    3.     # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
    4.     #
    5.     /[Ll]ibrary/
    6.     /[Tt]emp/
    7.     /[Oo]bj/
    8.     /[Bb]uild/
    9.     /[Bb]uilds/
    10.     /[Ll]ogs/
    11.     /[Uu]ser[Ss]ettings/
    12.    
    13.     # MemoryCaptures can get excessive in size.
    14.     # They also could contain extremely sensitive data
    15.     /[Mm]emoryCaptures/
    16.    
    17.     # Asset meta data should only be ignored when the corresponding asset is also ignored
    18.     !/[Aa]ssets/**/*.meta
    19.    
    20.     # Uncomment this line if you wish to ignore the asset store tools plugin
    21.     # /[Aa]ssets/AssetStoreTools*
    22.    
    23.     # Autogenerated Jetbrains Rider plugin
    24.     /[Aa]ssets/Plugins/Editor/JetBrains*
    25.    
    26.     # Visual Studio cache directory
    27.     .vs/
    28.     .vsconfig
    29.    
    30.     # Gradle cache directory
    31.     .gradle/
    32.    
    33.     # Autogenerated VS/MD/Consulo solution and project files
    34.     ExportedObj/
    35.     .consulo/
    36.     *.csproj
    37.     *.unityproj
    38.     *.sln
    39.     *.suo
    40.     *.tmp
    41.     *.user
    42.     *.userprefs
    43.     *.pidb
    44.     *.booproj
    45.     *.svd
    46.     *.pdb
    47.     *.mdb
    48.     *.opendb
    49.     *.VC.db
    50.    
    51.     # Unity3D generated meta files
    52.     *.pidb.meta
    53.     *.pdb.meta
    54.     *.mdb.meta
    55.    
    56.     # Unity3D generated file on crash reports
    57.     sysinfo.txt
    58.    
    59.     # Builds
    60.     *.apk
    61.     *.aab
    62.     *.unitypackage
    63.    
    64.     # Crashlytics generated file
    65.     crashlytics-build.properties
    66.    
    67.     # Packed Addressables
    68.     /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
    69.    
    70.     # Temporary auto-generated Android Assets
    71.     /[Aa]ssets/[Ss]treamingAssets/aa.meta
    72.     /[Aa]ssets/[Ss]treamingAssets/aa/*
    73.    
    74.     ######################################################
    75.     # macOS specific ignores
    76.     ######################################################
    77.    
    78.     # General
    79.     .DS_Store
    80.     .AppleDouble
    81.     .LSOverride
    82.    
    83.     # Icon must end with two \r
    84.     Icon
    85.    
    86.     # Thumbnails
    87.     ._*
    88.    
    89.     # Files that might appear in the root of a volume
    90.     .DocumentRevisions-V100
    91.     .fseventsd
    92.     .Spotlight-V100
    93.     .TemporaryItems
    94.     .Trashes
    95.     .VolumeIcon.icns
    96.     .com.apple.timemachine.donotpresent
    97.    
    98.     # Directories potentially created on remote AFP share
    99.     .AppleDB
    100.     .AppleDesktop
    101.     Network Trash Folder
    102.     Temporary Items
    103.     .apdisk
    104.    
    105.     ######################################################
    106.     # Windows specific ignores
    107.     ######################################################
    108.    
    109.     # Windows thumbnail cache files
    110.     Thumbs.db
    111.     Thumbs.db:encryptable
    112.     ehthumbs.db
    113.     ehthumbs_vista.db
    114.    
    115.     # Dump file
    116.     *.stackdump
    117.    
    118.     # Folder config file
    119.     [Dd]esktop.ini
    120.    
    121.     # Recycle Bin used on file shares
    122.     $RECYCLE.BIN/
    123.    
    124.     # Windows Installer files
    125.     *.cab
    126.     *.msi
    127.     *.msix
    128.     *.msm
    129.     *.msp
    130.    
    131.     # Windows shortcuts
    132.     *.lnk
    133.  
    Anyone has a suggestion what I could do to get rid of this issue?

    Greetings David
     
    Last edited: Jan 23, 2022
  25. D12294

    D12294

    Joined:
    Oct 6, 2020
    Posts:
    71
    My problem was that LFS was missing from Git on the Mac laptop. After LFS was installed and activated the project was cloned correctly and the references were set. So this helped me:

    1. Install homebrew from here https://brew.sh/index_de

    2. Install git-lfs with homebrew
    Code (CSharp):
    1. brew update
    2. brew install git-lfs
    3. use git-lfs before clone
    Code (CSharp):
    1. git lfs install
    2. git clone <clonepath>
     
  26. bugcamper

    bugcamper

    Joined:
    Mar 15, 2022
    Posts:
    9