Search Unity

Custom Assemblies are not reloaded if there is a compile error.

Discussion in 'Editor & General Support' started by MMOARgames, Jun 21, 2018.

  1. MMOARgames

    MMOARgames

    Joined:
    Feb 28, 2013
    Posts:
    24
    I've noticed that the custom assemblies are not reloaded if there's a compile error, but according to the docs the successfully build assemblies should be reloaded.

    According to the docs:
    This does not seem to be the case. After doing some testing I found that "Begin MonoManager ReloadAssembly" does not get raised after compilation is completed with errors, contrary to what the docs say.

    To test this out I made two folders

    Folder1
    -TestScript1.cs
    -TestAssembly1.amsdef
    Folder2
    -TestScript2.cs
    -TestAssembly2.amsdef

    In the TestScript1 class I subscribed to the CompilationPipeline events to make sure we're getting those dlls generated correctly.
    Code (CSharp):
    1. using System;
    2. using UnityEditor;
    3. using UnityEditor.Compilation;
    4. using UnityEngine;
    5.  
    6. [InitializeOnLoad]
    7. public static class TestScript1
    8. {
    9.     static TestScript1()
    10.     {
    11.         CompilationPipeline.assemblyCompilationStarted += CompilationPipelineOnAssemblyCompilationStarted;
    12.         CompilationPipeline.assemblyCompilationFinished += CompilationPipelineOnAssemblyCompilationFinished;
    13.     }
    14.  
    15.     private static void CompilationPipelineOnAssemblyCompilationFinished(string arg1, CompilerMessage[] arg2)
    16.     {
    17.         Debug.LogFormat("Compilation finished: {0}", arg1);
    18.         for (int i = 0; i < arg2.Length; i++)
    19.         {
    20.             switch (arg2[i].type)
    21.             {
    22.                 case CompilerMessageType.Error:
    23.                     Debug.LogError("---> " + arg2[i].message);
    24.                     break;
    25.                 case CompilerMessageType.Warning:
    26.                     Debug.LogWarning("---> " + arg2[i].message);
    27.                     break;
    28.                 default:
    29.                     throw new ArgumentOutOfRangeException();
    30.             }
    31.         }
    32.  
    33.         AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
    34.     }
    35.  
    36.     private static void CompilationPipelineOnAssemblyCompilationStarted(string obj)
    37.     {
    38.         Debug.Log("Starting Compile: " + obj);
    39.     }
    40. }

    In TestScript2 I kept clean with no extras

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class TestScript2 : MonoBehaviour { }

    After viewing the compiled output in the console, I deliberately added a compile error in TestScript2.cs and added an extra Debug.Log to TestScript1.cs in CompileFinished Event:

    Code (CSharp):
    1.  
    2. TestScript1.cs
    3. ...
    4.     private static void CompilationPipelineOnAssemblyCompilationFinished(string arg1, CompilerMessage[] arg2)
    5.     {
    6.         Debug.LogFormat("Compilation finished: {0}", arg1);
    7.         for (int i = 0; i < arg2.Length; i++)
    8.         {
    9.             switch (arg2[i].type)
    10.             {
    11.                 case CompilerMessageType.Error:
    12.                     Debug.LogError("---> " + arg2[i].message);
    13.                     break;
    14.                 case CompilerMessageType.Warning:
    15.                     Debug.LogWarning("---> " + arg2[i].message);
    16.                     break;
    17.                 default:
    18.                     throw new ArgumentOutOfRangeException();
    19.             }
    20.         }
    21.  
    22.      
    23.         Debug.LogWarning("I'm done!");
    24.    
    25.   AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
    26.     }
    27. ...
    28.  
    29. TestScript2.cs
    30.  
    31.  

    After saving and switching back to the editor to watch everything compile, I noticed that my new debug line didn't get thrown, which means the successful compiled assembly was not reloaded properly.

    View attachment 284021

    Odd thing is, if I were to close the editor and load it back up again, the successful compiled assembly is properly reloaded by the editor on startup.
     
    Last edited: Jun 21, 2018
  2. MMOARgames

    MMOARgames

    Joined:
    Feb 28, 2013
    Posts:
    24
  3. MMOARgames

    MMOARgames

    Joined:
    Feb 28, 2013
    Posts:
    24
  4. ludovicl_unity

    ludovicl_unity

    Joined:
    Mar 11, 2021
    Posts:
    1
    Hello MMOARgames,
    I know your post is old, but did you fix your issue?