Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by farhanblu · May 23, 2016 at 09:23 AM · scripting problempreprocessordefineglobalvariables

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?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image farhanblu · May 23, 2016 at 09:27 AM 0
Share

I also reimport a random script after making changes to rsp file. I am using C#.

avatar image Bunny83 · May 23, 2016 at 10:07 AM 1
Share

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.

avatar image farhanblu Bunny83 · May 23, 2016 at 11:36 AM 0
Share

Well, like you said, its greyed out only, but works at runtime! Sad, such visual bug wasted so much of my time. Thank you :)

avatar image Bunny83 farhanblu · May 23, 2016 at 11:52 AM 0
Share

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.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

50 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges