- Home /
Preprocessor for Unity version higher than 4.3
I need a way to define a preprocessor in C# that tell if the Unity version is higher than 4.3. In C++, it would be easy with .h but I'm not sure it's possible in C#. And I need that in the editor
ex:
#if UNITY_VERSION > UNITY_4_3
#define UNITY2D
#endif
#if UNITY2D
//do 2d stuff
#endif
Answer by Eric5h5 · Feb 11, 2014 at 02:53 AM
#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
#define PRE_UNITY_4_3
#endif
#if !PRE_UNITY_4_3
// do 2D stuff
#endif
Assu$$anonymous$$g you actually meant "equal to or higher". Since there's nothing newer than 4.3 at the moment....
Yes it's something like this I want. But is there a way to not doing that in every file? Like a C++ .h include?
I searched and I think it's impossible, so the only way is your answer in all file. Thanks
Is it possible to have a >= ? For current AND futur newer version of Unity3D ?
No, it's not. Preprocessor symbols are just symbols. You can check if it exists or not. The symbol doesn't have a value or something like that. They are like boolean switches.
They could have implemented something like version-feature switches, however since there are more and more breaks between newer and older version of Unity it would be pointless. There are newer things that doesn't exist in older versions as well as old things that doesn't exist anymore in current versions.
You should simply pick a $$anonymous$$imum version required and for small differences use preprocessor switches.
Who would develop something that relies heavily on Unitys 2D features and announce it to be compatible with Unity 2.6? Preprocessor switches can be used to fix for $$anonymous$$or differences between version. Though it always the best to use the most common features. For example the shortcut properties except "transform" has been removed. However GetComponent<SomeComponent>()
does work in all versions.
"however since there are more and more breaks between newer and older version of Unity it would be pointless"
Very true. Thanks for the insight.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can I create a global function/variable without a class in c#, or to skip reference to it? 1 Answer
Does Unity define a Preprocessor Directive for 'UNSAFE'? 0 Answers
An OS design issue: File types associated with their appropriate programs 1 Answer