Editor script that executes before build

Hi all

I want to write an editor script that will execute before the game is built. I’ve been looking around at the documentation for EditorApplication delegates, but I haven’t found anything appropriate. Does anyone know how I can do this?


Edit: IPreprocessBuild is Obselete, it’s replaced by IPreprocessBuildWithReport Unity - Scripting API: IPreprocessBuildWithReport

using UnityEditor;
using UnityEditor.Build;
class MyCustomBuildProcessor : IPreprocessBuild
     public int callbackOrder { get { return 0; } }
     public void OnPreprocessBuild(BuildTarget target, string path) {
     // Do the preprocessing here

Just add a script like this one to your project. Works fine in 5.6b.

Is there any way of doing something similar compatible with Unity 5.3.1f?

Been searching around but with no luck.

@INedelcu, that only works on 5.6+ the classes don’t exist in an earlier version of Unity.

Do your stuff, then execute the build using: