Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by CinnoMan · Oct 09, 2014 at 01:36 PM · preprocessor

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!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Oct 09, 2014 at 02:13 PM 1
Share

Sorry, had to change your title as it seems a "

avatar image CinnoMan · Oct 09, 2014 at 09:11 PM 0
Share

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... ;)

avatar image CinnoMan · May 02, 2018 at 11:03 AM 0
Share

nice find, thank you!

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CinnoMan · Oct 09, 2014 at 09:38 PM 0
Share

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)

avatar image
2

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CinnoMan · Oct 10, 2014 at 12:35 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

32 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity and Custom Defines 1 Answer

app with with multiple independent games 0 Answers

Values in editor script resetting 1 Answer

Property Editor - List with inheritance 1 Answer

preprocessor directivities with JavaScript 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges