Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Force script recompilation

Discussion in 'Scripting' started by cloral, Apr 2, 2013.

  1. cloral

    cloral

    Joined:
    Jan 25, 2013
    Posts:
    2
    Hello everybody. Our project has a settings menu that changes several compile defines via the gmcs.rsp and smcs.rsp files. Is there any way to force unity to recompile all the scripts when these files change? Otherwise users change settings and wonder why those changes aren't reflected when they run the game.
     
  2. Gibbonator

    Gibbonator

    Joined:
    Jul 27, 2012
    Posts:
    204
    I have a system that does something very similar. This is how I force a recompile:

    Code (csharp):
    1.  
    2.   AssetDatabase.StartAssetEditing();
    3.   string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
    4.   foreach (string assetPath in allAssetPaths)
    5.   {
    6.     MonoScript script = AssetDatabase.LoadAssetAtPath(assetPath, typeof(MonoScript)) as MonoScript;
    7.     if (script != null)
    8.     {
    9.       AssetDatabase.ImportAsset(assetPath);
    10.     }
    11.   }
    12.   AssetDatabase.StopAssetEditing();
    13.  
    I would be interested to know if there is a simpler/less expensive way to do it.
     
  3. schulkinator

    schulkinator

    Joined:
    Mar 13, 2013
    Posts:
    1
    I think I did something similar to what you did there, but you can simply break after the first script you touch, since all you really need to do is touch one script to trigger unity to recompile. Runs much faster than touching all the scripts.