Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Assembly Post Processing

Discussion in 'Editor & General Support' started by purestrain, Nov 4, 2016.

  1. purestrain

    purestrain

    Joined:
    Apr 7, 2015
    Posts:
    4
    Hello,

    i've written a post processor which rewrites some CIL-Code (Mainly generating specific functions to get rid of switch/case). Everything is working nicely inside the Editor (InitializeOnLoad) and its a huge performance benefit.

    Trouble comes when i create a player since all scripts are compiled again - but this time without calling my post processor. This means, that the base for e.g. ILCPP will be the unmodified assembly instead of the optimized one.

    Can i somehow create a hook between compilation and actual writing of the generated assembly-csharp file for the player?

    The only solution i know (and i think will work) is to create a dll with optimizations outside of unity, but the workflow will be a mess then.

    Greetings
    Michael
     
    AlkisFortuneFish likes this.
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,555
  3. purestrain

    purestrain

    Joined:
    Apr 7, 2015
    Posts:
    4
    Thanks, i guess i've got to stop my efforts then since it will probably never be done. Anyway, voted on this.
     
  4. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    958
    Voted too. With the new development model Unity is following, it's probably more likely to happen now than it was before, you just need to somehow remind Unity about it. Poking some devs might help!
     
  5. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Any updates on this? Is it possible to modify "Library/ScriptAssemblies/Assembly-CSharp.dll" within build pipeline?

    Related question: https://forum.unity3d.com/threads/an-assembly-mono-cecil-has-already-been-imported.473254/
     
  6. chrahunt

    chrahunt

    Joined:
    Apr 19, 2019
    Posts:
    1
    You can try something like

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. class PostprocessBuild : UnityEditor.Build.IPostBuildPlayerScriptDLLs
    3. {
    4.     public int callbackOrder {
    5.         get { return 1; }
    6.     }
    7.  
    8.     public void OnPostBuildPlayerScriptDLLs(UnityEditor.Build.Reporting.BuildReport report)
    9.     {
    10.         // Your code
    11.     }
    12. }
    13. #endif
    That seems to be invoked at the appropriate time to do assembly transformations.
     
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,555
    Can you access the DLL paths from the passed BuidlReport object? if not, it should've been designed that way, so you can actually easily get the paths to modify the assemblies you want.