Hello, I am looking for an insight into a recommended way to using preprocessor directives.
In my project, I use both the Unity Assertions (Unity Scripting API) and the Unity Profiler (Unity Manual). Both of them, I use as it is shown in the examples of their respective pages. However, I don’t understand how they behave when I don’t want them to be present.
In the Scripting API for Unity Assertions, it says:
From this, I get that if I do not define UNITY_ASSERTIONS, then my assertion calls aren’t included in my compilation. However, what happens to the function call itself? See this one:
public void Initialize(){
Assert.IsTrue(someCondition);
}
If I do not define UNITY_ASSERTIONS, what happens to this function call? Does it stick around, but doesn’t do anything or is it completely erased from the compiled code? My question aims at doing this:
public void Initialize(){
#if UNITY_ASSERTIONS
Assert.IsTrue(someCondition);
#endif
}
Is it necessary to do this or is it redundant? If it is redundant, why? From my point of knowledge, the function call still exists, it just doesn’t do anything because since once the symbol is undefined, it becomes hollow, not doing anything.
This question also leads me to my next one. In Platform Dependent Compilation (Unity Manual), they talk about the ConditionalAttribute Class of C-Sharp. If I understand it correctly, I would not do:
public bool MyEditorValidation(){
#if UNITY_EDITOR
// validating things for editor stuff
#endif
}
but instead I would write it like this:
[Conditional("UNITY_EDITOR")]
public bool MyEditorValidation(){
// validating things for editor stuff
}
Is this recommend to do once you have functions that should not be present entirely in your game, only in the editor and how does it relate to my previous question in this thread, about functions being stripped of their lines, but the function call itself remaining?