- Home /
distinguish between Editor versions. Minimum required version
Hi all
I have an asset on the asset store for which I added in-editor tooltips, which is a feature of Unity 4.5. In the script, I handle this by having a section that goes:
#if UNITY_4_5
//some code with tooltips
#endif
#if UNITY_4_3
//some other code
#endif
How can I write this instead, so I don't have to update this bit every time a new version of unity comes out? I'm looking for a way to say "if editor version is older than 4.5, do x, else do y"
I can see there's an "#else" command, but I don't know how to properly close the region it opens... :(
Any advice is much appreciated, thanks!
Sorry, had to change your title as it seems a "
ok, thanks for the info and for adjusting the title.
$$anonymous$$y backward compatibility goes only as far as 4.3, and if I interpret this manual bit about directives correctly, I might be able to do this by using #if #else and #endif in the proper order... ;)
Answer by Jopan · Oct 09, 2014 at 09:14 PM
Your problem, I think, is that you are using #endif after each if. I'm pretty sure you are supposed to not use it until after the entire ifelse chain.
#if UNITY_4_3 || UNITY_4_4
//do pre-4.5 code
#else
//code for all versions 4.5 and later
#endif
Yes, thank you, that is correct, doing it the way you suggest, it works now. (as I realized in a previous comment by having a look at the example code on the page about platform dependent compilation)
Answer by mgear · May 01, 2018 at 04:35 AM
looks like you can compare if version is newer than x, using: UNITY_X_Y_OR_NEWER
https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
Starting from Unity 5.3.4, you can compile code selectively based on the earliest version of Unity required to compile or execute a given portion of code. Given the same version format as above (X.Y.Z), Unity exposes one global #define in the format UNITY_X_Y_OR_NEWER, that can be used for this purpose.
Answer by Kiwasi · Oct 09, 2014 at 11:03 PM
If you check for the compatible you will always have to keep adding updates as the version goes up. The following code will break as soon as 5.1 comes out. You could try guessing the next series of numbers, the compiler allows you to write in defines that do not exist.
#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0
// Do new stuff
#else
// Do old stuff
#endif
If you check for the old versions you will have a much longer line of code, but it will not need updating as new versions come out.
#if UNITY_2_6 || UNITY_2_6_1 ... UNITY_4_2
// Do old stuff
#else
//Do new stuff
#endif
As of yet there is no < equivalency for defines.
yes, thanks, I went for checking for the old versions because there's currently not many that are supported (compatibility only goes back to 4.3 at the moment) and new versions of unity won't instantly break it. As a side note, what's up with v4.4? it can't be downloaded from the unity website and there's no define for it (unlike UNITY_4_3 and UNITY_4_5). was that version number skipped somehow?
Your answer
Follow this Question
Related Questions
Unity and Custom Defines 1 Answer
app with with multiple independent games 0 Answers
Values in editor script resetting 1 Answer