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

Question Auto refresh isn't working properly anymore

Discussion in 'Editor & General Support' started by LoneSurvivor82, Oct 22, 2021.

  1. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    41
    Hello,

    something has broken the autorefresh-function in my Unity. If I make changes to my scripts and build afterwards, the changes are not going into the build. But instead they do, if I explicitely uncheck the autorefresh-option and do a manually reimport of the changed script-file by doing a right-click and say "reimport" in the contextmenu.

    I tried a lot to somehow fix this problem. I updated to every new Unity version, now I am using latest 2020.3.21f1.
    I installed also to latest Visual Studio 2019 Community 16.11.5. It also happens if I am using another editor like Notepad++. Also the .meta-files in the project are not hidden.

    Is there anybody who can give me an advice? Is it somehow possible to write a custom plugin that somehow does my manually reimport-click on the changed files? A custom autorefresh so to say...

    Regards
    Lone
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,521
    So you mean if you edit a piece of code and type a gibberish error into it, then return to Unity, it lets you run in the editor even though there are errors?

    One thing is to try a reimport-all.

    Another thing to try is to make a new directory somewhere else and COPY the Assets, ProjectSettings and Packages folders from your project over to that directory, then tell Unity to open that.

    That will trigger a full reimport.
     
  3. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    41
    To be concrete, I don't type an error but I'm changing a custom class which inherits from a class in the Mirror Networking asset. The change can be minor like adding a new SyncVar-property (without referencing it or whatever). Then I hit build and try to test a multiplayer-session where the build started in my virtual machine is the host and the game started in the unity editor is the client.

    Somehow both versions differ which is confirmed by a corresponding exception thrown by Mirror.

    So I have two options to fix this: 1.) close unity, delete the whole Library/Artifacts-folder and restarting unity which then takes a lot time to reimport all files and do another build which is then working without any exceptions or
    2.) Like I wrote in the initial post, I turn off the autorefresh-option and do a manually reimport on the file(s) I was working on at last before hit build again which then brings a working build.

    Both ways are anoying because it takes time and are unnecessary steps I have to do.

    I also, like you suggested, created a new project in another location on another harddisk and copied the assets- and packages-folder which has the same effect that it works for the first time and then no more.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,521
    So this sounds more like some kind of state being preserved in Mirror... I know nothing about that package. Does it do any data analysis such as studying your syncvars and making some kind of WSDL to transport the data and then that fails to get updated??
     
  5. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    41
    Mirror Networking is an Asset that helps you making your game multiplayer-ready. You can do very high level things and then on start or building, it has some weaving mechanism inside that adds some additional networking code to the classes which do the rest of the communication.

    You can find Mirror here: https://assetstore.unity.com/packages/tools/network/mirror-129321

    I don't believe that it's mirror's fault but somehow Unity. There are some other older threads in the forum about similar problems like this one: https://forum.unity.com/threads/script-changes-dont-compile.486287/
     
    Last edited: Oct 23, 2021
  6. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    41
    Maybe I found a workaround. I would enjoy to solve the problem by its root but I've spent so many time to find the reason for the problem without success and run off ideas what it could be so at least this would save me some annoying clickwork.

    I wrote two classes which listen to the OnPreBuild- and OnPostBuild-Events which uncheck the AutoRefresh-checkbox, then do a refresh of the AssetDatabase and after build, check the AutoRefresh-checkbox again if it was checked before.

    Maybe it's helpful to other developers who suffer by the same problem.
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.Build;
    3. using UnityEditor.Build.Reporting;
    4. using UnityEngine;
    5.  
    6. namespace Assets.MyGame.Editor.Common
    7. {
    8.     public class PreprocessBuild : IPreprocessBuildWithReport
    9.     {
    10.         public static bool AutoRefreshWasActivated;
    11.  
    12.         public int callbackOrder { get; }
    13.         public void OnPreprocessBuild(BuildReport report)
    14.         {
    15.             AutoRefreshWasActivated = EditorPrefs.GetBool("kAutoRefresh");
    16.             if (AutoRefreshWasActivated)
    17.             {
    18.                 Debug.Log("AutoRefresh was activated -> disable");
    19.                 EditorPrefs.SetBool("kAutoRefresh", false);
    20.             }
    21.  
    22.             AssetDatabase.Refresh();
    23.  
    24.             Debug.Log($"PreprocessBuild.OnPreprocessBuild for target {report.summary.platform} at path {report.summary.outputPath}");
    25.         }
    26.     }
    27. }
    28.  
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.Build;
    3. using UnityEditor.Build.Reporting;
    4. using UnityEngine;
    5.  
    6. namespace Assets.MyGame.Editor.Common
    7. {
    8.     public class PostprocessBuild : IPostprocessBuildWithReport
    9.     {
    10.         public int callbackOrder { get; }
    11.         public void OnPostprocessBuild(BuildReport report)
    12.         {
    13.             Debug.Log($"AutoRefresh has {(PreprocessBuild.AutoRefreshWasActivated ? "": "not ")}been activated");
    14.             EditorPrefs.SetBool("kAutoRefresh", PreprocessBuild.AutoRefreshWasActivated);
    15.  
    16.             Debug.Log($"PostprocessBuild.OnPostprocessBuild for target {report.summary.platform} at path {report.summary.outputPath}");
    17.         }
    18.     }
    19. }
    20.  
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,521
    Gosh, this certainly seems like something that the package SHOULD take care of. You might want to ask around the mirror support area (wherever that is?) to see if others have this pain; it is VERY rare for you to be the first person to find pain. Usually pain has been found by 10,000 people long before you find it.
     
  8. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    41
    I already did talks to the Mirror Support (you can do that on discord) and as they can't reproduce this behaviour on their example-code (and me neither), they blame Unity. :rolleyes:
     
  9. LoneSurvivor82

    LoneSurvivor82

    Joined:
    Aug 17, 2019
    Posts:
    41