Automate Unity Building
It took me hours to figure out how to create a simple build script in Unity, even after watching videos, I was really confused. So why not write an article so that other developers won’t need to spend that much time themselves.
Before we get started make sure you have the necessary build supports needed. In Unity Hub you can see your installations.
If not, you’ll have to click the three dots, and then click “Add Modules.”
Next, we will need to create a script named something like
Make sure this file is placed in
This file will be responsible in calling Unity BuildPlayer as well as adding menu items for you to quickly build for your platform(s) of choice.
Next copy the code below. Disclaimer: this code uses the scenes from your build settings so make sure the scenes there are correct. You can ignore the last function if you want, I just kept it there in case you need to use Asset Bundles (I did not). With this script you can call the build methods from “File > Build All” and Unity will build the players to the “Builds” directory in your project root.
This takes care of building from the editor but what if you were using CI/server to build it for you? You will need to make a shell/batch script or you can use Python so that the OS won’t matter.
You may have to modify some variables such as
UNITY and also the zipping process if you don’t want to zip the builds.
You may also pair this up with an Ino setup script like so
I hope you found this tutorial helpful because I sure would’ve.