- Home /
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?
Thanks, Ves
Answer by INedelcu · Dec 31, 2016 at 12:58 PM
Edit: IPreprocessBuild is Obselete, it's replaced by IPreprocessBuildWithReport https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.html
#if UNITY_EDITOR
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
}
}
#endif
Just add a script like this one to your project. Works fine in 5.6b.
I have a similar need and wondering if anyone has any suggestions. Due to the lack of nested prefab support in Unity I have some custom handling of certain GameObjects that are part of the scenes when referring to prefabs. Basically they have the ability to swap out the prefab or update it on the fly without being an actual prefab instance or having lost their prefab connection.
I was wanting to have this on the fly logic run when the scene is being built rather than when the game is running. Actually I need that to happen because some of these are networked game objects and throwing them out at runtime to be replaced with fresh prefabs breaks the networking id system.
Basically was looking for something like OnBeforeBuild() callback on $$anonymous$$onoBehavior?
This was exactly what I was looking for, helped me to find it at least. I was looking for PostBuild. But this helped me get there. Thank you!
Please note for Unity 2018.1 and above, the interface IPreprocessBuildWithReport should now be used ins$$anonymous$$d as IPreprocessBuild has become obsolete.
Answer by eexxoo · Aug 07, 2017 at 02:51 PM
Is there any way of doing something similar compatible with Unity 5.3.1f?
Been searching around but with no luck.
I sell a build config tool on the asset store which lets you define build configs and set up builds. I just pushed some changes to do pre-build steps as well because I needed exactly this feature in 5.4.3. If you're interested, check it out here http://u3d.as/12$$anonymous$$t
Answer by Graham-Dunnett · Jul 17, 2013 at 08:39 PM
Do your stuff, then execute the build using:
http://docs.unity3d.com/Documentation/ScriptReference/BuildPipeline.BuildPlayer.html
Thanks, I guess that works, it's a shame there isn't a preBuild delegate though
Answer by plasticYoda · Feb 11, 2017 at 07:40 PM
@INedelcu, that only works on 5.6+ the classes don't exist in an earlier version of Unity.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110322im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Up to date Unity building placement code/tutorials? 1 Answer
Does Unity decompress Truecolor RGBA format textures when loading? 0 Answers
Can't Build PC Standalone due to multiple namespace script errors but playable in editor 1 Answer