public bool featureEnabled; // so that feature can be enabled/disabled in UnityEditor
void Update(){
if (featureEnabled){
doFeature();
}
}
if i set featureEnabled to false in UnityEditor, and then build the program for deployment, will the compiler remove the check for featureEnabled? In other words, is the optimization smart enough to determine that featureEnabled will always be false, and just remove the check and the block of code in the if statement altogether? (I would expect traditional C/C++ compilers to do this optimization. No idea if C# will do this)
I don’t think the compiler is able to optimize that out. Search for “Global custom #defines” on this page for a supported way of doing this: Unity - Manual: Conditional compilation
You can use preprocessor directives to include or exclude code based on the custom defines.
I understand the use of #defines from the C/C++ world.
For rapid prototyping, I was thinking it would be easier just to check/uncheck the box for the feature in the Unity Editor, and rebuild to test something out, vs. modifying a text file to enable/disable the feature with a #define.
I guess with the #define route, I should create an include file with all of the #defines, and include this with every other file.