# Unity3D Build Configuration for Deployment/ Publish

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
{
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
BuildPipeline.BuildPlayer(buildPlayerOptions);
}
}


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

#if DEV_BUILD
Debug.Log( "Hi from Dev Build" );
#endif


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

var envi = test

#if UNITY_IOS
envi = ios
#elif UNITY_ANDROID
envi = android
#endif


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
https://docs.unity3d.com/ScriptReference/Debug-isDebugBuild.html

var envi = prod
if (Debug.isDebugBuild) {
envi = test
}

• 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. – HappyGuyDK Nov 23 '18 at 13:30
• 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. – Kieron Nov 23 '18 at 14:20
• I might have misunderstood you. I edited my answer with another example which I'm assuming was the answer you were actually looking for? – HappyGuyDK Nov 23 '18 at 21:51