Search Unity

Bug Prefabs randomly losing references throughout our project - reimport fixes it

Discussion in 'Prefabs' started by Xarbrough, Jun 12, 2020.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Over the past few months, my team has been experiencing an annoying problem with prefabs: Suddenly our game is broken and developers need to investigate until they find object fields in the inspector of some prefab that are not assigned correctly. Then we start the typical "hey designer x, why didn't you assign this correctly?" only to find out, that it was indeed set up correctly and is still correct on other computers. We then manually reimport a chain of prefabs (variant + base) or delete the entire library and suddenly the issue is fixed.

    To me, this can only mean that there's an issue in the prefab systems or with the AssetDatabase v2.

    Has anyone seen this and knows more?

    We're close to a deadline and I'm afraid I don't have the time to provide a reproduction project, but I can only say that the issue has been happening every couple of days over the past months. Unity 2019.3.3 - 2019.3.13.
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    JesOb and Xarbrough like this.
  3. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @Xarbrough

    Yes we have seen many of these cases and we have fixed many of these issue. In fact I am pretty confident the latest version of Unity have solved most if not all of them.
     
    JesOb and Xarbrough like this.
  4. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    That's great news, thank you!
     
  5. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
    Hey, we've been having this problem for a very very long time. We're now on 2019.4.11f1, and it happens almost daily with some of our prefabs. It happens on prefabs which have been present in the project for a very long time, and which have had no script modifications for months. Needless to say, this is extremely frustrating.

    We've been trying all sorts of workarounds but nothing helped. Please don't ask me to send a repro project, because there are no stable repro steps. Our repro steps are:
    1. Do whatever work on the project
    2. Use version control
    3. Wait for plenty of references in apparently random, recently untouched prefabs to inevitably disappear

    Not very helpful, I know, but it's the best I've got.

    The next workaround we're going to try is to make a bunch of Addressables instead of directly referencing the prefab files.
     

    Attached Files:

  6. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
    @runevision @SteenLund Sorry for the poke, but I would really appreciate an answer on this. The issue is getting out of hand on our project and we feel completely powerless about it. Wherever we look for help, we have to provide exact repro steps for our issue to even be considered by the Unity team, but we can't provide that with this seemingly random issue. We need help but can't find any.

    I've attached another example of this happening today, still in Unity 2019.4.11f1. The only clue we can think of that seems to apply to most if not all instances of this problem, is that it looks like the missing references are always in lists of an abstract type. In this case I'm attaching right now, Pickupable is an abstract type, and the exposed List contains prefabs with the Weapon component, which inherits Pickupable.

    Over the months, this is starting to cost us a LOT in work time. Please help.
     

    Attached Files:

  7. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Do you know when it usually happens? e.g. getting latest from version while having the editor open?
     
  8. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
    Hey, thanks for the quick reply.

    It's very hard to tell if that's related to the issue, since we're a team of 16 people. If you think that might be a potential cause, we can try enforcing the rule of always closing the editor before pulling, and then I can report back here if the problem persists.

    Thanks for the example! If you have any other ideas of whatever might help isolate the issue, please feel free to let me know.
     
  9. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
    Well in fact, I can pretty much confirm that that's not causing the issue. We have an automated build machine which pulls the latest version, and then produces a build using Unity in -batchmode -norender, and these builds frequently have the issue as well.
     
  10. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
    Bump. Please help.
     
  11. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
  12. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I don't have any ideas.
     
  13. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
    Ok...? So the plan is just for us to keep working with this bug forever? There's no way for us to get help from Unity?
     
  14. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    We need to be able to reproduce an issue to be able to investigate it. In rare cases we might be able to make educated guesses about a cause and implement a blind fix even though we can't test if it even works, but this is rarely viable or possible, especially with complex issues. So without a repro project and repro steps, we're pretty much as stuck as you are. I don't know if you could work with Enterprise Support to somehow investigate the issue right on your machine when it happens, but this is not something our team is involved with, so not something I know much about. We fix bugs based on bugs reports that QA has been able to reproduce.

    But apart from that, I was only speaking on my own behalf. I don't have any ideas. I can't say if Steen does.
     
  15. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
    I understand all that. But would it be possible to maybe try to work together to find ideas of ways to isolate the cause of the issue? I know full well that a problem can't be fixed without a solid repro, but that's the core of our team's real problem: we have no idea how to isolate that solid repro. Nothing we've tried to either "de-randomize" the bug's occurrence or to make it disappear so far has worked at all.

    We could very much use the insight of someone who worked on the system for clues as to what to try and investigate in order to be able to find that.
     
  16. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    36
    Hi @Emery-Monzerol . As stated before, it would be really be helpful for us getting a project copy (including library folder) when you have a missing reference. Having this we could investigate the issue and likely find the root cause. My understanding is that the missing reference you get doesn't get fixed by unity restart and therefore a project+library copy will be useful for us to investigate.
     
  17. Emery-Monzerol

    Emery-Monzerol

    Joined:
    Nov 1, 2012
    Posts:
    20
    Hi @volblob73 , thanks for the response. I don't believe that option was stated before, thanks for putting it on the table. I don't have the authority to decide whether I can send over my team's project and we have an urgent deadline this week, so I will discuss this option next week with the rest of my team and I'll let you know as soon as I know if I can do that.
     
  18. volblob73

    volblob73

    Unity Technologies

    Joined:
    Sep 19, 2017
    Posts:
    36
    Ok sounds good. If you decide to report a bug and upload project+library, I would suggest that you first verify that you can still see the missing reference when using the project+library copy.
     
  19. rchapman

    rchapman

    Joined:
    Feb 13, 2014
    Posts:
    105
    Just went through the painful process of tracking down and fixing a bunch of prefabs. Here's one example of before & after that will hopefully help. In this case, the base prefab defines two Array elements that are empty, set there as placeholders for variants. This is the root prefab:

    Root object:
      ShowWhenAttached:
    - {fileID: 0}
    ShowWhenDetached:
    - {fileID: 0}


    This is the broken prefab variant:
          propertyPath: ShowWhenAttached.Array.data[0]
    value:
    objectReference: {fileID: 9033093010934296128}
    - target: {fileID: 4961026042056194972, guid: f3561776cc99646408c461883c551c97,
    type: 3}
    propertyPath: ShowWhenDetached.Array.data[0]
    value:
    objectReference: {fileID: 498759996121807741}
    - target: {fileID: 4961026042056194972, guid: f3561776cc99646408c461883c551c97,
    type: 3}


    This one is after. Note that the objectReferences are all the same, but the Array.size property is now set:
          propertyPath: ShowWhenAttached.Array.size
    value: 1
    objectReference: {fileID: 0}
    - target: {fileID: 4961026042056194972, guid: f3561776cc99646408c461883c551c97,
    type: 3}
    propertyPath: ShowWhenDetached.Array.size
    value: 1
    objectReference: {fileID: 0}
    - target: {fileID: 4961026042056194972, guid: f3561776cc99646408c461883c551c97,
    type: 3}
    propertyPath: ShowWhenAttached.Array.data[0]
    value:
    objectReference: {fileID: 9033093010934296128}
    - target: {fileID: 4961026042056194972, guid: f3561776cc99646408c461883c551c97,
    type: 3}
    propertyPath: ShowWhenDetached.Array.data[0]
    value:
    objectReference: {fileID: 498759996121807741}
    - target: {fileID: 4961026042056194972, guid: f3561776cc99646408c461883c551c97,
    type: 3}


    I realize this is kind of a degenerate case in that setting up an empty array could cause issues, but the very frustrating part of this is that it seemingly randomly stripped all of the variants and broke a bunch of builds. It's not clear what caused this. In this case it seems like it imported the variant before the base and lost track of the size of the array?

    I'm looking through Git to look for other patterns. Hopefully this will help track down at least one more cause of this. We're on 2019.4.15f1 for this project.
     
  20. rchapman

    rchapman

    Joined:
    Feb 13, 2014
    Posts:
    105
    Further to above, the variants *without* the Array.size property were working fine until very recently on my machine (and still all working fine on other devs' machines).
     
  21. gazbushell

    gazbushell

    Joined:
    Feb 5, 2009
    Posts:
    53
    using 2020.3.4f1 - still an issue. To be honest i have only found this thread today and I have just been managing with the bug but its now happening more frequently so i searched it. Originally, it was difficult to find the cause of this problem. i spent ages running through all aspects of my code.. now I have a step to check... see if any prefabs have lost their references. Fortunately, all my prefabs are in a _prefabs folder so I can simply right click and reimport the whole folder which doesn't take too long since they are just prefabs and variants and it solves the missing references. (I would prefer not to have to worry about this tho...)
    It happens in-between updating scripts and compilation. Not every time and I cannot reproduce reliably. I can usually tell when its happened when I get a bunch of unexpected null reference exceptions and I have actually put custom warnings into my scripts to let me know if references have been lost... When it happens I reimport the prefabs folder and run again and its generally ok... Its not a perfect solution, but we work with what we've got, right?
    If any one has a solution to this (because its been happening on my main project since being in 2020.3..) that would be great. I thought maybe it might be an editor setting? one of the compile after playing etc Any way just thought I would chip into the conversation :)
     
  22. gazbushell

    gazbushell

    Joined:
    Feb 5, 2009
    Posts:
    53
    also - I am a plasticSCM user... just saying in case that may have something to do with it.
     
  23. Tony1974

    Tony1974

    Joined:
    May 26, 2018
    Posts:
    11
    Been having the same problem for a while now.

    Often I will make a seemingly innocuous code change and then suddenly a prefab reference in entirely unrelated part of the game loses it references. Eg I had 4 Prefab Wing tip trail Game Objects referencing a special effect prefab and 1 of them suddenly lost its reference while rest were fine. This after adding two lines of code that were nothing to do with these game objects. The code changes also compiled fine.

    It's as if Unity constantly re-establishes the references at each save/load but sometimes encounters issues and instead of informing the user, simply doesn't set it and moves on. Immensely frustrating.

    I'm using Unity 2020.2.2f1. Yes I know I should upgrade to .3 but every time I upgrade things break and I lose several days trying to fix it (another painful feature of Unity). That's time I don't have right now.
     
  24. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    305
    This happened for the first time when I upgraded to Unity 2019.4.28f1
    Prefabs dont have references when instantiated or when selected from the editor, but if I open it I see all the references in it.
     
  25. Deleted User

    Deleted User

    Guest

    @Hazneliel same here. Same version upgrade caused a couple of prefabs loosing it. Reimport helped
     
  26. CannedCaveman

    CannedCaveman

    Joined:
    Feb 28, 2020
    Posts:
    2
    Exact same as @Hazneliel and @Alexees. Just upgraded to 2019.4.28f1 from 2019.4.16f1 and for the first time ever I have this problem. I see in the inspector that my spawned player sets a reference in a script in my scene (set it to public to check), but the script gives the no reference error when I want to call a method on the script that has been referenced. This has worked forever until now. I'll try reimporting.
     
  27. LucaNeUnity

    LucaNeUnity

    Joined:
    Jul 23, 2018
    Posts:
    1
    Same here @volblob73, just tried both 2019.4.15 and 2019.4.33
     
  28. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    I can confirm this happens in 2022.1A15 and A16. Just had this issue and had to reimport.

    EDIT: I fixed this by reimporting all, then when variables were correct, I used a script to detect all prefabs and marked them dirty.

    Then saved and quit editor.

    Upon restart it didnt happen again.
     
    Last edited: Dec 3, 2021
  29. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    NVM...it just came back a while later. Can we pls fix this? Thanks
     
    hassanali4 likes this.
  30. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Another update: Deleting the Library folder fixed the issue.
     
  31. figbash

    figbash

    Joined:
    May 13, 2008
    Posts:
    60
    We are experiencing this on our project in 2021.2.3, are there any updates to it?
     
  32. figbash

    figbash

    Joined:
    May 13, 2008
    Posts:
    60
  33. krisventure

    krisventure

    Joined:
    Mar 24, 2016
    Posts:
    118
    Oh my god I was so scared for some 5 minutes until I've found this thread and realized I can fix it by re-importing. I'm using Unity 2020.3.5f1 and the bug still exists here. Although first time for me.

    Without being able to reproduce, to give some details (in case it helps pinpointing the issue):

    I had nested prefabs in the scene, a parent prefab that included other prefabs. I went inside one of the child prefabs of a child prefab and edited something harmless, a collider's radius, I'd done similar edits in that child prefab many times before. What I don't remember if I saved the change in the child prefab and then hit play without returning to the top-level scene hierarchy (I do that mistake sometimes) or did I exit the prefab view before entering Play Mode.

    But as soon as in Play Mode, it started to throw errors and then I noticed that all the child prefabs in the main parent prefab that contained the edited grandchild prefab suddenly showed "Missing Prefab" in the hierarchy (and it wasn't even brown color like when you delete a prefab).

    I tried reloading the scene, restarting Unity but the Missing Prefab issue remained in every affected scene. The weirdest thing was that the Prefab was only reported 'Missing' when I was in top-level scene hierarchy and it couldn't access the child prefabs from that level of hierarchy (or in Play Mode). But when I opened the parent Prefab for editing, it showed all the child prefabs inside fine, they were all linked correctly in that view, the same ones that were reported missing in the top hierarchy.

    I almost decided to revert to a previous day's backup (would've been a day's work lost) but luckily I've found this thread and a simple re-importing of the parent prefab fixed everything.
     
  34. arkore

    arkore

    Joined:
    Dec 14, 2017
    Posts:
    2
    Steps to reproduce issue (Unity 2018.3.0f2):
    1. Prefab object with child object with SpriteRenderer, empty Animator, and Script with public variables. Disable prefab.
    2. Prefab variant of prefab
    3. Prefab variant of variant. So, now Item1 -> Item2 -> Item3
    4. Customize variants
    5. Copy animation controller and animation files from something similar
    6. Edit script of prefab, adding public animator variable, and boolean.
    7. Reorder some existing variables (this probably broke everything) in script. Move some variable lines of code higher up.
    8. Open prefab. Enable prefab.
    9. Set anim controller.
    10. Edit animitor, changing animation clip to be the copied one.
    11. Make new animation with new sprites.
    12. Delete old property and frames from animation
    13. Disable prefab, and exit prefab mode.
    14. Play game

    Step 7 (or both step 7 and 8) is probably what caused the variants to all break and revert to their original state of prefab.

    Sometimes the bug is different, in that it will change some variable references to prefabs (on my Pool object/script) from referencing the prefab in my assets, changing to referencing a copy of that prefab in my scene instead. Very strange and unexpected. It's happening more often now, and so I've stopped dragging prefabs into my scene for testing, or have limited it greatly by deleting them from my scene soon after im done. In my scene, i have these prefabs enabled when testing, while they are disabled in their prefab configuration.

    I don't plan on updating Unity. The updates have always contained things I don't want, and didn't ask for. And according to my research (the comments above), this bug is still happening in Unity 2021. I would rather install just a patch that Unity could release for this issue.

    I may try to downgrade Unity to before prefabs, or stop I'll using prefab variants. If I still experiencing issues, then I may stop making prefabs altogether, and just make everything as objects in my scene, in disable parent pool-like object/enclosure and reference from that.
     
    Last edited: Feb 15, 2022
  35. IronHelmet

    IronHelmet

    Joined:
    May 2, 2017
    Posts:
    85
    Our issue might be slightly different, we have seen it two or three times in the last few weeks in 2020.3.27. Upon opening the editor after a perforce sync, some team members see a warning that there is a missing prefab with guid xxx. Upon opening the prefab that contains the missing asset, we see a little red prefab icon. I have searched the whole project, and even rolled back month of work and searched again, but as far as I can tell we have never had an asset with the guid reported in the error.
     
  36. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    219
    Anyone in this thread: Please report a bug with a project that has the setup and describe the reproduction steps. That will greatly help us investigate what the issue is and get it fixed.
     
  37. IronHelmet

    IronHelmet

    Joined:
    May 2, 2017
    Posts:
    85
    If you like, I'm sure we could set you up with a perforce seat for our project, you could sync, and the next time we see the problem you could sync again and see the missing resource notification. Would that be useful?
     
  38. Mads-Nyholm

    Mads-Nyholm

    Unity Technologies

    Joined:
    Aug 19, 2013
    Posts:
    219
    Yes indeed, that would be helpful.
    You can DM me when it happens next time with the info needed. Thank you.
     
  39. bome99

    bome99

    Joined:
    Sep 14, 2009
    Posts:
    119
    I have the same bug.
    Has anyone reported this yet?
    It looks like @arkore has a way of reproducing it
     
  40. bome99

    bome99

    Joined:
    Sep 14, 2009
    Posts:
    119
  41. bome99

    bome99

    Joined:
    Sep 14, 2009
    Posts:
    119
  42. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    97
    There definitely still is a bug in Unity 2021.2.5f1 regarding asset import. We are constantly getting same import errors with the same prefabs. Reimporting manually always fixes the errors but it is tedious to do...

    upload_2022-9-13_12-22-27.png

    upload_2022-9-13_12-22-47.png

    On reimport we also usually get this error message (however the import still fixes the prefab):
    > Assertion failed on expression: 'm_Blacklist.count(artifactKey) == 0'

    Please Unity fix this!!!
     
  43. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    632
    2021.2.5f1 is more than 9 months old now, is 14 2021.2.x revisions out of date, and is no longer supported (update to 2021.3 LTS to see any updates). Fixes ship with new Editor versions, there's nothing they can do if you're going to keep using an out of date version.
     
  44. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    97
    We cannot update to a newer Unity version since some 3rd party assets (i.e. UniStorm) do not support those newer versions.
     
  45. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    632
    Well, you're SOL until those assets receive support. Again. Not something to complain to Unity about.
     
  46. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    We are on 2021.3.23 Problem is still here. IT seems like 2021 is the most bugged version of unity I have been working on.
     
    Last edited: Apr 21, 2023
  47. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    49
    2022.2 checking in, problem exists here too. I didn't really start taking a look into this until recently, but it's been something I've noticed for quite a while now (definitely during 2021.x, probably well before that).

    My experience with this problem has been the following (this is a rough summarization): I'll have a large Prefab object, call it a level, it contains all the various constituent required parts, a mix of GameObjects, Prefabs, Prefab variants, etc. Sporadically, after the domain is reloaded, or during application shutdown (the editor itself, not just exiting from Playmode), I'll notice that one, or many, of the level Prefabs has changed via git status. It's at this point where the fun begins, and I attempt to track down what has changed. What I usually see via the inspector is that Rooms within the Level will have sub components with fields where the object references of those fields point to another Room. A straightforward solution is to simply create a Type for those fields, add the Type to the subcomponent, and then hide the field from the inspector (ex. remove the SerializeField attr). Then it's trivial during initialization to assign the value of those fields using the Type. The frustrating part of this is that the prefab that gets changed by Unity hasn't been updated or otherwise modified, and finding the field(s) with the bad references can be tricky.

    The other use case that is less frequent is just simply having a field in the Inspector that loses the reference to its object all together, and has a value reported as 'missing GameObject' by the Inspector. This one is relatively easy to detect using the methodology outlined in: Finding Missing Object References In Unity.
     
  48. alexsmith123

    alexsmith123

    Unity Technologies

    Joined:
    Jan 11, 2022
    Posts:
    27
    Hi kayroice,
    Could you please report this bug with a project and reproduction tests?
     
  49. JTAU

    JTAU

    Joined:
    May 12, 2019
    Posts:
    24
    Also having this occur in 2022.3.1f1 LTS. For me it's happening sometimes when I make a minor change to a prefab and save it, the separate scriptable object that referenced the prefab shows that prefeb as "missing" (even though its still there exactly where it was).
     
  50. Peter_Olsted

    Peter_Olsted

    Unity Technologies

    Joined:
    Apr 19, 2021
    Posts:
    75
    @JTAU Could you submit report a bug ?