Is there the option within Unity3D to specify build configurations?

My goal is relatively simple - when building for mobile stores (Play Store/ App Store) I want to make sure my app is pointing to the production services, rather than the test one I use in the editor/ testing on devices.

It's controlled by a field on a MonoBehaviour currently, but we I need to remember to flip it from Test to Production before doing a build and publish.


Unity's build system is very scriptable, would have a look at their Build Player Pipeline docs, and BuildPipeline.BuildPlayer

You can use the sample code the provide as a base for creating menu items you select that initiate builds with a specific configurations. I would use this in conjunction with Scripting Define Symbols that to define DEV_BUILD or PRODUCTION_BUILD so you can use preprocessor checks wherever they're needed.

For example, this would create a menu item for initiating a Development iOS build -- could set a method for each platform / target:

public class MyBuildController 
    [MenuItem("Build/iOS Dev")]
    public static void BuildiOSDev()
        // setup basic build options (scenes, platform, target directory)
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scene1.unity", "Assets/Scene2.unity" };
        buildPlayerOptions.locationPathName = "iOSBuild";
        buildPlayerOptions.target = BuildTarget.iOS;
        buildPlayerOptions.options = BuildOptions.None;

        // set scripting define symbols so can use conditional compilation for things that target Dev / Production
        PlayerSettings.SetScriptingDefineSymbolsForGroup( BuildTargetGroup.iOS, "DEV_BUILD" );

        // start build

Your code can then use conditional compilation to include or exclude code that should run when targeting a dev build:

Debug.Log( "Hi from Dev Build" );

I believe this article might have some answers for you https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

Simply check what platform you're on and set the production service accordingly.
Works the same in both C# and JavaScript.

var envi = test

  envi = ios
  envi = android

You can also make a development build (checkmark in the build menu) and use the Debug.isDebugBuild to check if the current build is a development build

var envi = prod
if (Debug.isDebugBuild) {
  envi = test
  • \$\begingroup\$ I believe you should be able to write #if UNITY_IOS || UNITY_ANDROID if you wish to check for both just like a regular if() but I haven't tested it. \$\endgroup\$ – HappyGuyDK Nov 23 '18 at 13:30
  • \$\begingroup\$ Thanks @HappyGuyDK. That's not quite what I was after. For example, I'm building for Android right now, but need it pointing at the test environment. \$\endgroup\$ – Kieron Nov 23 '18 at 14:20
  • \$\begingroup\$ I might have misunderstood you. I edited my answer with another example which I'm assuming was the answer you were actually looking for? \$\endgroup\$ – HappyGuyDK Nov 23 '18 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.