In 5.5 it seems that if you #define an identifier, you can no longer use the identifier with the conditional attribute.
E.g.
The identifier ENABLED is defined but ignored by the conditional attribute.
#if UNITY_EDITOR || DEVELOPMENT_BUILD
#define ENABLED
#endif
public class MyClass
{
[Conditional("ENABLED")]
public static void MyFunc() { }
}
I found this report on Issue Tracker which says that it’s by design. So why was this changed? I haven’t seen a mention of this change in release notes.
Chiming in here as we’re having the same issue. We use this very feature to remove Debug logs from production builds (which gives a big speed/memory improvement). Any word on why it was removed?
With some quick further testing, it only seems to affect the [Conditional] attribute; if you use the custom define in a normal manner (i.e. wrapping code in an #if/#endif block), it’s fine
This kind of makes this the whole Conditional attribute useless.
We use this for removing Debug logs from production builds. Previously, we had the defines in the class that we call to log the message (essentially a wrapper for Debug.Log… calls), like this:
Based on this change, I now need to include the defines in every class, which makes it unusable. Defining them in ClassA doesn’t bring it over to ClassB, even though ClassA is created before ClassB.
@andymads has the right of it. From what I could find, this is the only way to globally define something in Unity? Without hacking something I mean. If anyone has another/better way, I’ll gladly take it.
For those that are looking for it, while in the past you might have defined your constants like this:
into the Scripting Define Symbols box. One added benefit for this system (depending on how you’re using your constants) is that you can separate the define per platform, so in our case, editor builds automatically have logs while iOS/Android builds don’t.