- Home /
custom defines not reflected in Mono
I'm using Unity 5.3.4 on a mac machine. I'm adding global defines to my unity project but they don't seem to reflect in MonoDevelop. I don't want to define them in the Player settings (Scripting Define Symbol section), instead I want to go the smcs.rsp (placed in Assets folder) route. The content of my smcs.rsp file is
-define:ENABLE_A
And I am using it as following :
#if ENABLE_A
Debug.Log("WORKS");
#endif
But the debug statement is always greyed out. What am I doing wrong here?
I also reimport a random script after making changes to rsp file. I am using C#.
Well, is it just "grayed out" in VisualStudio / $$anonymous$$onoDevelop or does it not work as well? What happens when you reimport the script and run the game? Do you see the Debug log?
$$anonymous$$eep in $$anonymous$$d the "smcs.rsp" is a pure compiler setting. I doubt that this information is copied into the VS project settings but directly used by the compiler. So the IDE has no idea they exist.
You also might want to read the very last paragraph on this page. It depends on your targetplatform which compiler is used, so you might need a different settings filename.
Well, like you said, its greyed out only, but works at runtime! Sad, such visual bug wasted so much of my time. Thank you :)
It's not a bug at all. The "smcs.rsp" file is a configuration file for the compiler. The mono compiler is a seperate program which is just used by Unity to compile your scripts. This config file has no meaning to the IDE especially because the IDE doesn't even know which compiler Unity is going to use.
Answer by kart_ranger · Oct 18, 2017 at 09:27 PM
Make a EditorWindow and handle all your defines in there make use of PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, GetMCSDefines() + GetCustomDefines());
or
Make a python script, call it from C# when scripts compile, modify the csproj, it is just a xml. (a little ok method), below is a sample, but get the namespace during runtime, I hardcoded it
import xml.etree.ElementTree as ET
import os
namespaces = {'ns': 'http://schemas.microsoft.com/developer/msbuild/2003'}
ET.register_namespace('',"http://schemas.microsoft.com/developer/msbuild/2003")
csproj = os.path.dirname(os.getcwd()) + '/' + 'Assembly-CSharp.csproj'
# print os.path.dirname("Assembly-CSharp.csproj")
tree = ET.parse(csproj)
root = tree.getroot()
for elem in root.iterfind('.//ns:PropertyGroup[@Condition]', namespaces = namespaces):
defines = elem.find('.//ns:DefineConstants', namespaces = namespaces);
if(defines != None):
defines.text = defines.text + "MY_DEFINES"
tree.write(csproj)
Your answer
Follow this Question
Related Questions
How to exclude code if a certain script is not present in the project. 2 Answers
Preprocessor #defines and Conditional compilation in scripts 0 Answers
Why do placing a preprocessor directive inside another causes my script to lose proper indentation? 1 Answer
Vuforia enabled scripting define 0 Answers
app with with multiple independent games 0 Answers