I just tested changing to Conditional and it is still not working.
I copied the code from the msdn link and tested and the Conditional is always evaluating to false and removing the method.
#define TESTERSYMBL // comment this out for another test.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
public class ConditionalTest : MonoBehaviour {
// Use this for initialization
void Start () {
testcall();
}
[Conditional("TESTERSYMBL")]
void testcall()
{
print("This was called.");
}
}
No, doesn’t work for me. I have the #define and also tried adding the using System.Diagnostics statement to the top. this used to all work fine a few versions of Unity ago but at some point it stopped, not sure which version. I’m using 5.6.2 and having the conditional attribute just greys out the calls to these functions, if I comment out the attribute then the functions get called just fine (and are no longer grey).
Have you tried adding the define in the build settings’ “Scripting Define Symbols” ? Although I’d assume it should also work using a standard #define (but I’ve never tried it that way).
Using the #define is not working for me on a mac with unity 5.6p1, however, I was able to get this working by adding the variable to the Scripting Define Symbol. It was way better when you could do the #define but I guess this is better than not working at all!
I submitted a bug to Unity (case 934431) about it; and according to the feedback I got the behaviour of the conditional attribute in Unity versions before 5.5 was incorrect according to the C# standards; and it’s now working correctly.
then I would have to do one or both of the following
define CONDITIONAL_LOG_FUNCTION in all .cs files in which I want calls to DbgLog.ConditionalLog to have some effect
add CONDITIONAL_LOG_FUNCTION to the preprocessor defines in player settings to have calls to DbgLog.ConditionalLog work globally
Obviously what is happening is that if CONDITIONAL_LOG_FUNCTION is not defined in any given .cs file, then all calls to ConditionalLog in that file magically disappear during the compilation process (I believe they’re removed at the MIL → native stage of the compilation process).
I can confirm that both of these approaches work for me.