How can a variable on an object in a scene be set by a build script?

We have a feature settings script that contains feature flags that can be turned on or off and affect how things behave at runtime. For example, an isBeta flag. If that is turned on, it displays to the user on the UI that it is a beta release. When doing a manual build via the editor, that flag is toggled on the object in the scene, then the build generated.

For running a build via command line, it is done with a static function that runs BuildPlayer, and the following command (from the docs):
“C:\Program Files\Unity\Editor\Unity.exe” -quit -batchmode -projectPath “C:\Users\UserName\Documents\MyProject” -executeMethod MyEditorScript.PerformBuild

Is there a way that static function MyEditorScript.PerformBuild can change a variable in scene? So that we could, say, specify a beta or non-beta build via command line.

Open to suggestions for alternative ways to implement that type of feature flag. Something like a config file that is read at runtime, like stored in json or something readable is not a great solution as users could easily change it.

It very much sounds like you need to define some custom conditional defines (compiler directives)…

Your flags\settings can then be wrapped around the defines, for example…

#if DEV_BUILD
  float characterSpeed = 2f
  boolean invincible = true;
#elif #PROD_BUILD
  float characterSpeed = 1f
  boolean invincible = false;
#endif

Hope this helps.

2 Likes

@PeachyPixels , great suggestion, thanks.

1 Like