Execute editor code before Build Run

I am trying to automate clearing a few prefab properties before I build to device. I figured a MenuItem that does that and then calls Build Run would be a good solution, but no matter what string I try I get something like:

I know there is the BuildPipeline.BuildPlayer option, but I would rather use the settings I have set in editor already and for each device instead of having to re-create all that in code and keep it up to date.

Any other/better options to do what I am trying to do? For example, even better might be if Unity had some kind of hook before building I could just piggy back on instead of having to create a MenuItem.

Bump

You could totally do what you are trying to do with 1 line of code that is equivalent to “Build and Run”. Just need to pass the scene list and the currently active platform to BuildPlayer pretty much.

Thanks, I guess I will play with that more, I was just hoping that I had the syntax wrong on my ExecuteMenuItem, but maybe Unity just does not allow you to execute items in the “File” menu? I wasn’t able to get any of them to work.

I was also hoping to find something that I could hook into Unity’s existing build process so that I didn’t have to train myself to use my build option vs the built-in one.

Over time you will likely end up using scripted builds anyways. So it won’t be a waste of effort, trust me. :slight_smile:

Ah ha!!! I found the hook I was looking for:

PostProcessSceneAttribute
http://docs.unity3d.com/Documentation/ScriptReference/PostProcessSceneAttribute.html

Ugh, but now I can’t find a way to check if I am just doing a “Play” in editor vs a build for a device. Application.Platform says editor on both scenarios using this hook :frowning:

I’m not fully following what you are meaning without seeing code, so this is just a guess: perhaps this is useful to you.

http://docs.unity3d.com/Documentation/ScriptReference/EditorApplication-playmodeStateChanged.html

Hmm yeah, that might do the trick, will take a look, thanks.

After messing with this all some more, I think you are right, in the long-run I will be better served just scripting my builds.