I want to automate some of my Unity build process. I know that setting up automatic builds for platforms is relatively easy, just start Unity headless and tell it to build platform X!

This is fine for most things however I have some platform specific things for a given platform. For example I have achievements for Steam, GoG and my own thing if you are running truly standalone. I can easy switch between them by setting #define STEAM_BUILD to make a build with steam features enabled. This is setup for each platform that I support.

At the moment I have to change the script manually and re-build every time. I want to make a build server do this all for me but how do I tell Unity to build my PC version with a certain #define X set?


1 Answer 1


Use Application.RuntimePlatform to determine in code which platform you're on.


You can also specify a build target on the commandline, which will set the appropriate #define for the target in question.

-buildTarget <name>


The #defines are listed here:


If you need seperate builds for Windows and Windows with Steam, then you can set other preprocessor definitions in a text asset:

You can define your own preprocessor directives to control which code gets included when compiling. To do this you must add a text file with the extra directives to the Assets folder. The name of the file depends on the language you are using. The extension is .rsp: C# (player and editor scripts) /Assets/mcs.rsp UnityScript /Assets/us.rsp

As an example, if you include the single line -define:UNITY_DEBUG in your mcs.rsp file, the #define directive UNITY_DEBUG exists as a global #define for C# scripts, except for Editor scripts.

Every time you make changes to .rsp files, you need to recompile in order for them to be effective. You can do this by updating or reimporting a single script (.js or .cs) file.


  • \$\begingroup\$ So I would have to edit the .rsp file every time that I want to build for a given platform rather than the script? That just moves the problem somewhere else... Or can I have multiple .rsp files and selectively use them? \$\endgroup\$ Commented Sep 24, 2017 at 16:39
  • 2
    \$\begingroup\$ You can generate the .rsp file with a script. I am speaking from professional Unity game dev experience; it's how we do it at work. \$\endgroup\$
    – Almo
    Commented Sep 24, 2017 at 23:44
  • 1
    \$\begingroup\$ That makes more sense \$\endgroup\$ Commented Sep 25, 2017 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .