Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Unity Addressing issues with missing references

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

  1. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    17
    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.
     
    ModLunar, joshcamas, sirxeno and 3 others like this.
  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:
    17
    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:
    17
    Fix will be available in 2019.3.15f1.
     
  5. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,015
    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:
    605
    Xarbrough likes this.
  7. KAJed

    KAJed

    Joined:
    Mar 15, 2013
    Posts:
    90
    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:
    17
    @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:
    90
    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:
    17
    @KAJed do you have a case number for that issue?
     
  12. KAJed

    KAJed

    Joined:
    Mar 15, 2013
    Posts:
    90
    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:
    17
    @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:
    216
    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,160
    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:
    290
    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:
    90
    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:
    183
    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:
    415
    @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:

unityunity