Addressing issues with missing references

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:

  • 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.

  • 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.

  • 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.

7 Likes

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?

Yes, you need to use Asset Database v2 for this fix. Any specific reason why you are using v1?

Fix will be available in 2019.3.15f1.

This is great news! Is the fix also on 2019.4 LTS?

Edit: Yes it is!

@Xarbrough_1 Yes it is

1 Like

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.

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.

1 Like

@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.

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.

1 Like

@KAJed do you have a case number for that issue?

My case number for the issue is 1263658. There were unable to reproduce the issue in house but for me it was 100% repro.

@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.

We’re on 2019.4.15f1 and experiencing broken prefab references quite often:

Only forcing Unity to rebuild its Library fixes those references. It seems as if there’s still a pretty annoying bug in the asset referencing system somewhere.

3 Likes

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.

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’…

Not sure if this is the exact problem mentioned in the OP but I get a NPE in my script

Destroyer dstr = Instantiate(Resources.Load("Prefabs/Destroyers/myprefab"), sometransform) as Destroyer;
if (dstr.someBool) ...  // dstr null

but then the object is instantiated correctly in the scene. Using 2019.4.18f1 LTS

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.

Looks like 2020.2.4 has caused a regression in this issue and it is happening again

7 Likes

@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).