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 jimbobuk · Jan 11, 2010 at 03:44 PM · iphonemonopreprocessor

How can i use C#'s Conditional Attribute in Unity iPhone?

I'd like to try and make some code debug only, as such i'd like to remove as much of it as possible when i'm making a release build. According to this page

http://weblogs.asp.net/tgraham/archive/2004/03/12/88682.aspx

C# has just such a thing to do this, in its Conditional attributes. Yet i've tried this in unity iPhone and it doesn't seem to compile. I'm not sure whether this works in standard unity or not with its more up to date mono implementation, but i've asked elsewhere what version of mono unity iphone uses to try and track down this problem.

I've tried

#define ENABLED

...

...

[ConditionalAttribute("ENABLED")] // doesn't seem to compile :(

static public void DebugFunc(object val) {}

I've also tried using ConditionalAttribute("ENABLED") and Conditional("ENABLED"), neither working.

Anyone got any idea why this doesn't work? It could be VERY VERY helpful!!!

Cheers

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by azupko · Jan 11, 2010 at 06:35 PM

Conditionals do work with mono (at least with 2.6.1) but I have never tried with iPhone. #if #endif definitely do work however... not sure if that helps...

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
1

Answer by jimbobuk · Mar 06, 2010 at 12:21 AM

I seem to be able to make this work by doing this

using ConditionalAttribute = System.Diagnostics.ConditionalAttribute;

not sure whether this is since the latest 1.6 version of Unity iPhone or not.

I just can't tell whether this will compile out any calls to the function at the callee point. ie. if you are calculating strings as params will these whole steps be skipped if conditional attribute is used to remove the function you are calling.

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 TowerOfBricks · Jul 29, 2012 at 06:38 PM 0
Share

I tested it. So created some simple cases and then inspected the IL code. It turns out that even though I am calling non-constant functions, it will be stripped out. All arguments and any calculations/function calls done in the arguments will be stripped. A bit unexpected, but it's useful.

avatar image gilley033 · Aug 20, 2013 at 04:43 AM 0
Share

Using the Conditional Attribute removes the call to the method it's used on, which is why the calculations/function calls done in the arguments are stripped out. Extremely useful indeed!

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

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

What version of mono does Unity iPhone use, and are there any differences between unity's mono and standard mono? 1 Answer

Can Unity Iphone game be written in C#? 4 Answers

Problem with video in IOS 1 Answer

How to check what iDevice your using and adjust GUI sizes according... 1 Answer


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