Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Prefabs are reimporting every time a code change is made

Discussion in 'Editor & General Support' started by L42yB, Jul 27, 2020.

  1. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    188
    Hi @Menion-Leah

    The bug is fixed and is currently being backported to 2020.2, and once that lands it will be backported to 2019.4.

    I would expect the code to land in 2019.4 in a couple weeks, and then be bundled with a new 2019.4 release after that, so it could be 3-4 weeks, if all goes well.
     
    futurlab_xbox and Menion-Leah like this.
  2. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Great, thank you for your quick answer!
     
    Unity_Javier likes this.
  3. SideSwipe9th

    SideSwipe9th

    Joined:
    Jan 10, 2019
    Posts:
    46
    @Unity_Javier wanted to give you a quick update. I added those scripts you provided to both of our projects.

    So far the only concrete thing they've revealed is that whatever is causing prefabs to be reimported and assets in the projects I'm working on to be reimported upon a code change is not assembly version related. Your scripts are helpful though, and they've given me some insight for where to hook into the asset import pipeline to do before/after comparisons for why an asset is being reimported upon a code change. Just need to get the time to do it now.
     
    ROBYER1 likes this.
  4. Craig87

    Craig87

    Joined:
    Feb 17, 2014
    Posts:
    7
    I was having a similar issue to this thread, but instead of re-importing on every code change, Unity was re-importing on every prefab change in the "Open Prefab" screen. When I have my UI prefab open it would re-import every 2 seconds, making UI changes very difficult.

    My solution was to uncheck the "Auto Save" in the Scene window (the box is next to the Gizmo's check box).

    I understand its not the same issue as this thread, however I found this thread when trying to identify a solution, so others might be hitting the same problem.
     
  5. SideSwipe9th

    SideSwipe9th

    Joined:
    Jan 10, 2019
    Posts:
    46
    Just to give a quick update for folks here, I've been able to make a minimum viable project that demonstrates Unity editor erroneously reimporting assets after entering and exiting play mode, and then saving the currently active scene. I've submitted it as a bug report.

    I've attached to this reply the scripts I used to help diagnose the issue. The AssetHashOnDiskAtStart script uses Odin Inspector to provide inspector buttons. If you don't have Odin, either remove/comment lines 35-69, or create your own custom inspector buttons to invoke the same functions. These scripts will output the Asset Dependency Hash for any assets that are about to and have finished going through the asset import pipeline to the debug log. You can then check if the hash is the same whenever the scene starts (AssetHashOnDiskAtStart), before the asset is about to be saved (AssetModificationDebugger), and after the asset has been processed (ReimportDebugger). If the hash is the same at all of these steps, and the contents of the asset is the same on disk both before you enter play mode, and after you exit play mode and save the scene, then I believe you are experiencing the same issue and Unity is wrongly reimporting files.
     

    Attached Files:

    futurlab_xbox likes this.
  6. SideSwipe9th

    SideSwipe9th

    Joined:
    Jan 10, 2019
    Posts:
    46
    Another quick update for the people following the thread.

    After some digging by Javier, the bug that we were able to report appears to be caused by the Substance Painter plugin from Allegorithmic/Adobe. Any material which has a .sbsar texture will be forcibly reimported by the plugin upon exiting play mode. If this material is part of a prefab, due to dependencies this can also cause the prefab to be reimported as well.

    We should be filing a bug report with Adobe directly in the next day or two. A possibly related issue with a workaround that I've not tested yet was reported on the Substance forums back in November, and linked here.

    I hope to get some time on the second of our two projects in the coming weeks, it too is having random prefab imports upon exiting play mode, but isn't reliant on Substance. Unfortunately the issue in that project while frequent, still has an unknown trigger so I wasn't able to replicate it in a bug report. I'll update again when I have more information.
     
    futurlab_xbox and Unity_Javier like this.
  7. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    188
    Just a heads up, the fix has been backported to 2020.2.4f1 (which should be out "soon") and the 2019.4 backport is on its way as well.
     
  8. futurlab_xbox

    futurlab_xbox

    Joined:
    Nov 5, 2018
    Posts:
    22
    We're facing very frequent full asset reimports in our project (Unity 2020.2.2f1) and still trying to narrow it down... But with regards to this specific Substance issue, I had reported the bug: https://forum.substance3d.com/index.php?topic=35746.0

    Unsurprisingly, they haven't done anything about it yet, but there's a workaround for it. Just add this script to a object on your scene when playing on Editor:

    Code (CSharp):
    1. public class SubstanceReimportBugWorkaround : MonoBehaviour
    2. {
    3.  
    4. #if UNITY_EDITOR
    5.     private void OnDestroy()
    6.     {
    7.         Substance.Game.Substance.ClearSubstanceList();
    8.  
    9.         var fieldInfo = typeof( EditorApplication  ).GetField( "playModeStateChanged", BindingFlags.NonPublic | BindingFlags.Static );
    10.         var eventHandlerList = fieldInfo.GetValue( null ) as Delegate;
    11.  
    12.         var invocationList = eventHandlerList.GetInvocationList();
    13.         for ( var index = 0; index < invocationList.Length; index++ )
    14.         {
    15.             var listener = invocationList[ index ];
    16.             var declaringTypeFullName = listener.Method.DeclaringType.FullName;
    17.             if ( declaringTypeFullName.ContainsFastIgnoreCase( "Substance" ) )
    18.             {
    19.                 Debug.LogFormat( $"[SubstanceReimportBugWorkaround] Removing {declaringTypeFullName} from EditorApplication.playModeStateChanged's invocation list to avoid unnecessary asset reimports...");
    20.                 var playModeStateChangedAction = listener as Action< PlayModeStateChange >;
    21.  
    22.                 EditorApplication.playModeStateChanged -= playModeStateChangedAction;
    23.             }
    24.         }
    25.     }
    26. #endif
    27.  
    28. }
    29.  
     
    SideSwipe9th likes this.
  9. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    188
    A little update on this issue, the fix for Prefabs reimporting everytime when using Assembly Auto-versioning has been backported to 2019.4.23f1, so just keep an eye out for when that drops.

    @futurlab_xbox happy to help if you can provide some more details, in case its not the Assembly auto-versioning issue and not the Substance issue either.
     
  10. futurlab_xbox

    futurlab_xbox

    Joined:
    Nov 5, 2018
    Posts:
    22
    I don't recall any more instances of this error after making the changes to the Assembly auto-versioning bits and updating Unity to 2020.2.5f1 - thank you very much for your help!
     
    Unity_Javier likes this.
  11. mikelortega

    mikelortega

    Joined:
    Feb 5, 2014
    Posts:
    47
    Unity 2019.4.23f1 is out, but the problem mentioned in this thread seems to be still present. The issue code 1294785 is not in this release's known issues or fixed list.
    In my case when I change a texture or it's properties all fbx using this texture are reimported. This behaviour is still present in Unity 2019.4.23f1. I thought it would be fixed in this version, but this might be another issue?
     
  12. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    188
    Hi @mikelo ,
    Thanks for pointing out the release note was missing. I spoke to our release managers and they added it to the release notes as:
    • Asset Pipeline: Fixed an issue with Prefabs reimporting every time a code change is made. (1294785)

    As for the behaviour you're describing, with models reimporting every time a texture change happens, that sounds like it shouldn't happen.
    Do you have some AssetPostProcessor that might be influencing this when calling OnPostprocessTexture?
     
    Menion-Leah likes this.
  13. mikelortega

    mikelortega

    Joined:
    Feb 5, 2014
    Posts:
    47
    Thank you @Unity_Javier, you are right, the problem has been fixed in 2019.4.23f1
    It seems I have a problem with OnAssignMaterialModel that I use that to collect materials that are created during import. I'll have to think about a workaround to do this. Many thanks!
     
    Last edited: Mar 26, 2021
    Unity_Javier likes this.
  14. EP-Toushirou

    EP-Toushirou

    Joined:
    Nov 19, 2019
    Posts:
    40
    Hello Can it Fix in 2020.3.14? I wait for server months fixed on 2020.3, but I can't see the sure date. Thanks
     
  15. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    188
    Hi @EP-Toushirou
    The fix should be available in 2020.3 as 2020.3 branched off 2020.2 with the fix in 2020.2.4f1

    If you’re still getting unexpected imports maybe its a separate issue like @mikelo had earlier in this thread. Could you describe the problem so that we can provide some more help?
     
  16. EP-Toushirou

    EP-Toushirou

    Joined:
    Nov 19, 2019
    Posts:
    40
    But I see the known issue still has this problem
    upload_2021-7-5_11-31-45.png
    so i want to know can the 2020.3.14f1 fix it.
     
  17. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    188
    Hey @EP-Toushirou, thanks for raising this.
    Just had a look at the internal notes for this bug and it looks like it hasn't been addressed for 2020.3 in general (which is odd since 2020.3 should branch off of 2020.2).
    Anyways, I'll reach out internally and get this moving.

    Edit: 2020.3.14f1 has the fix.
     
    Last edited: Jul 5, 2021
  18. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    188
    Hi @EP-Toushirou just got word from our internal QA that the issue is not present on 2020.3.14f1, so it should be safe to upgrade to that revision.

    But again, if this is still happening it could be possible that you're seeing another issue and we would be happy to have a closer look at it.
     
  19. EP-Toushirou

    EP-Toushirou

    Joined:
    Nov 19, 2019
    Posts:
    40
    Thanks a lot, I will upgrade to the newest version.
     
    Unity_Javier likes this.
  20. GalStil

    GalStil

    Joined:
    May 3, 2017
    Posts:
    1
    Hello there! i am having the same problem.

    where can i download this version? i can only see2020.3.13f1
     
    futurlab_xbox likes this.
  21. WildframeXbox

    WildframeXbox

    Joined:
    Oct 13, 2017
    Posts:
    18
    Hello! Is this fix also available in any Unity 2021 version?

    Thanks!
     
    Mishganches likes this.
  22. Mishganches

    Mishganches

    Joined:
    Mar 23, 2014
    Posts:
    31
    It looks that the problem still exists in version 2021.3.7f1. Prefab variants have been reimported on each change of base prefab.
     
    Last edited: Oct 6, 2022
  23. ge01f

    ge01f

    Joined:
    Nov 28, 2014
    Posts:
    121
    Im in 2020.3.37f1, much later than this was reported to be fixed, and it still appears to be occurring. Lots of time importing prefabs, when I make changes in the editor to things that should not be updating any data fields in the prefabs. Any code changes at all, and the prefabs import.

    I didnt see it until I had 2600 prefabs with common scripts, and now it's happening all the time.
     
    Mishganches likes this.
  24. Paul-Swanson

    Paul-Swanson

    Joined:
    Jan 22, 2014
    Posts:
    317
    Iv Come across this before and here's how I fixed it. Check to see if you have any unitypackage files just sitting in your assets directly. Until I removed all mine same exact issue on any version 2019+. And the reason why this is more and more common as time goes is because of the unity asset store policies. Most makers create there assets on standard render. But to sell them as hdrp/urp (even though they are easily converted with a non special shader) you have to add a a package to modify them to claim it with your check box. And I'm guessing the connection here is the way asset refresh database was coded.

    Package manager dls the package puts in in ur project drops them in. Then removes that package.
    So.im guessing when we update those prefab it's getting unintentionally flagged and thus anything related to that content I'd gets reimported. Iv tested this several time . And everytime, remov9ng all the .Unitypackage files fixes it.
     
  25. Hayden-Verbrec

    Hayden-Verbrec

    Joined:
    Sep 14, 2022
    Posts:
    11
    I'm getting exactly the same issue here on the currently supported LTS.

    Every change, either in code, on prefabs, or even opening prefabs within the scene causes massive reimporting times.
     
  26. tanatos

    tanatos

    Joined:
    Oct 8, 2014
    Posts:
    6
    This problem still occurs on multiple Unity versions including 2019.4, 2020.3, 2021.3...
     
    Last edited: Jan 16, 2023
  27. tanatos

    tanatos

    Joined:
    Oct 8, 2014
    Posts:
    6
    BUMP - this issue is making us waste a lot of hours of work.
    Developers spend a few hours per day just waiting for the constant prefab re-imports.
     
    YaGa likes this.
  28. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    188
    Hi @tanatos ,
    If this issue is happening on 2021.3, what is the Import Activity Window saying is the cause for these assets to be reimporting?
    If there's no reason for the re-imports stated, then there must be a call to AssetDatabase.ImportAsset which is force reimporting it. Would you be able to share a repro project in that case so we can get to the bottom of it?