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 eshan-mathur · Feb 23, 2016 at 07:31 PM · xcodedebugpreprocessor

Is there a way to tell if Xcode is set to Debug vs. Release within Unity?

Is there a way to tell if Xcode is set to Debug or Release within C# / Unity? Some kind of static class or # define?

I'm specifically talking about the "Build Configuration" dropdown in the Edit Scheme menu. This can be set within Unity using the "Run in Xcode As" dropdown in Build Settings.

Mind you I'm not talking about the Development Build checkbox in Unity. Just Xcode (or platform, whatever). I'd like to run platform-specific build-configuration-specific code.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by eshan-mathur · Feb 24, 2016 at 05:14 AM

I ended up deciding not to do this. My goal was to tie my own debug code (debug menus, in-game tools, etc.) to the Xcode build configuration setting so that they would never get out of sync and I'd only have to set Debug vs Release in one place.

Ultimately the realization was that at some point I will want to test a release candidate version of the game (none of my "debug" code) with all the native Debug mode stuff on (profiling, debugging, etc.). Tying them together would rob me of this flexibility.

For now I'm just making a checkbox somewhere.

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
avatar image
2

Answer by psydent · Feb 24, 2016 at 01:32 AM

You have to write a plugin to handle this at runtime. Because the Build Config can be set in Xcode after Unity has generated the project, all the code at the Unity level (C#) must be compiled into the Xcode project. Whether you run it or not needs to be gotten from the native level.

Here's some code that I whipped together but did not test and may need revisions, such as exception handling, updated preprocessor directives, and a different default return value based on your use cases. You could call it once when your game launches and then keep the bool value in a C# script somewhere so you only incur the overhead of calling native code once.

Something like in an Objective-C plugin (.mm) you have:

 extern "C"
 {
     bool _IsBuildConfigDebug()
     {
     #if DEBUG
         return YES;
     #else
         return NO;
     #endif
     }
 }

And then you have to have in a C# script:

 using System.Runtime.InteropServices;
 
 [DllImport ("__Internal")]
 private static extern bool _IsBuildConfigDebug();
 
 public static bool IsBuildConfigDebug()
 {
     #if !UNITY_EDITOR
         #if UNITY_IPHONE || UNITY_TVOS
         return _IsBuildConfigDebug();
         #endif
     #endif
     return false;
 }

There might be a simpler way to do this by reading the Build Config setting you set in the drop down of build options, but it won't be able to change if you change the setting in Xcode. You would have to rebuild your Xcode project from Unity if you want to change from a Debug to a Release build config, which I recommend staying away from.

Hopefully this helps. Maybe I can post an example, but don't hold your breath.

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
avatar image
0

Answer by phil_me_up · Feb 23, 2016 at 07:39 PM

It's been a while since I checked, but I'm pretty sure that XCode uses the DEBUG define when in a debug build, so #ifdef DEBUG should be what you're looking for.

You can set your own defines per schema, but as Unity will rebuild your XCode project that's not so useful (unless you want to start running post build processes to modify the project, which is an option).

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 eshan-mathur · Feb 23, 2016 at 07:55 PM 0
Share

Nope, for some reason even when Build Configuration is set to Debug in Xcode, the "#if DEBUG" define is still false in Unity/C# land. I just did a test by changing the "Run In Xcode As", which successfully changed the Build Configuration setting in Xcode, but had no impact on that define.

avatar image phil_me_up eshan-mathur · Feb 23, 2016 at 08:15 PM 0
Share

Ah sorry, I didn't read your question properly.

What you're trying to achieve I assume, is to write something in C# that will only happen when XCode is set to release build and not debug (or visa versa).

I would have thought that http://docs.unity3d.com/ScriptReference/Debug-isDebugBuild.html would be a good start, although I don't know for sure that it's what you're after or how it will be compiled out for release builds.

EDIT: Sorry, that's for the development build, not the XCode project settings... I'm sure I've done this before. I'll go check....

avatar image
0

Answer by TimHeijden · Nov 19, 2016 at 04:00 PM

For those who want to get the editor setting and use it in an editor script:

For (at least) Unity 5.4 or higher, there is a property in EditorUserBuildSettings called iOSBuildConfigType. This may be exposed in Unity 5.5 but it isn't in 5.4. That said, you can still retrieve it using reflection:

 System.Reflection.PropertyInfo pi = typeof(EditorUserBuildSettings).GetProperty("iOSBuildConfigType", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
 
 // Static class has no instance, so null's as variables
 int val = (int)pi.GetValue(null, null);
 
 // 0 == Debug, 1 == Release

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

40 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

Related Questions

Latest Unity version debug error in iOS 1 Answer

Debug.log output is not showing in device console for ios6 1 Answer

Is there a way to have debug code compiled out for a final build? 5 Answers

Less verbose Debug.Log ( Xcode ) 0 Answers

iOS Xcode - Debug Output (Neatly) 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