6

Is there a way to run a script method automatically before I build via File > Build Settings... > Build?

I know I can make a menu item to call my method and call build afterwards.

Steven Mills
  • 2,363
  • 26
  • 36
Roberto
  • 11,557
  • 16
  • 54
  • 68
  • AFAIK you can only execute scripts after building via [PostprocessBuildPlayer](http://docs.unity3d.com/Documentation/Manual/BuildPlayerPipeline.html). Can you explain the purpose of your script in more detail so we can look for an alternative way. – Kay Dec 06 '13 at 09:05
  • My script just builds and copies the resulting DLLs of some plugins into the Plugins folder. – Roberto Dec 06 '13 at 12:38

2 Answers2

11

You can Use IPreprocessBuildWithReport interface in Unity 5.6+

AminSojoudi
  • 1,904
  • 2
  • 18
  • 42
  • 1
    I don't even remember why I wanted that, but this is awesome, thanks! Is it in the release notes? – Roberto Apr 24 '17 at 20:06
  • 1
    `IPreprocessBuild` is obsolete! Use [IPreprocessBuildWithReport](https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.html) instead! – asj Jul 18 '22 at 14:04
2

AFAIK, Unity API doesn't offer any pre-processing/pre-building capabilities connected to the build command from the menu.

But on the other hand, you can make an editor script that does all the process from building your DLLs, importing them and then building your app. Take a look at the BuildPipeline to achieve this purpose.

This way you can write your own pipeline. But you will need to call this from an editor script though, not from the menu as you asked for in your question.

Kryptos
  • 875
  • 8
  • 19