Distinguish one build from another in code?

I’m about to build a “demo” version of my game, which is mostly a subset of the full game, but just including one or two scenes. There are some things I’ve like to do within the demo that I wouldn’t normally do in the full game. For example, after finishing the demo content, I’d like to jump to another scene than the game would normally go to when completing that level.

I use BuildPipeline.BuildPlayer() to create my builds. I was wondering if there was some way to set a constant, so that in my scripts I can do something like if (SomeStaticClass.IsDemoVersion) {}, so I can do things differently in the demo than I normally would.

Currently, I see that I can add arbitrary files to my build. So, worse-case, I could add a “demo” file, or something like that, and check for its existence when running. But that seems a little messy. I was hoping there might even be an option for setting a pre-compile variable, so that I could do something like #IF UNITY_EDITOR, only more like #IF DEMO_VERSION

Search for “global custom defines” here: Unity - Manual: Conditional compilation

1 Like

Thanks. I’ll see where that gets me. It’s not immediately obvious whether this will work for a command line build process. I may need to create the RSP file prior to calling BuildPipeline.BuildPlayer(), and then delete the RSP after to prevent it from being used by my other builds. I’ll see how it goes.

1 Like