Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 KEELAN · Jul 02, 2015 at 09:40 AM · c#debugpreprocessor

How to use #define to turn debug information on/off

Hi,

I want to use #define in my scripts to show debug information;

 #define isDebug
 ...
 ...
 
 public class Example: Monobehaviour {
 
 void Update() {
 #if isDebug
 //SHOW DEBUG INFORMATION
 
 #endif
 }
 }

I have never used them before and the documentation seems vague. If I use it like that, how do I then turn the debug off/on.? Kind Regards

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by fafase · Jul 02, 2015 at 10:11 AM

In the PlayerSetting, you can find a Scripting Define Symbols.

You can add your DEBUG case in there and remove it when you go for a production build.

Other way you have to remove the define manually from the script.

Comment
Add comment · Show 2 · 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
avatar image KEELAN · Jul 02, 2015 at 10:23 AM 0
Share

Thank you for the reply. Is the only way to have debug information optional easily (from the inspector) and have it not in the build version to do something like this

 #if UNITY_EDITOR
 public bool showDebug=false;
 
 if(showDebug)
 // show debug information...
 #endif
avatar image fafase · Jul 02, 2015 at 10:30 AM 0
Share

using a basic public variable is more flexible since a macro cannot be changed at runtime. So if you go with DEBUG it will be all the way.

now having the public var allows you to change anytime in a more flexible way.

Depending where you need the code, you can use platform macros:

http://docs.unity3d.com/$$anonymous$$anual/PlatformDependentCompilation.html

so if you want your code to run only in editor but not on the device:

 #if UNITY_EDITOR
    $$anonymous$$y$$anonymous$$ethodOnlyInEditor();
 #endif

this will not even go in any build as the compiler will ignore that bit of code. Still when running in the editor, it will run.

$$anonymous$$aybe give a little extra info on what you want to achieve so that we can help you out better.

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

21 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to use Application.logMessageReceived for logging ? 3 Answers

Source file could not be found - Unity 2018.2 4 Answers

How to get an object to move your camera while being confined to a circle 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