Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 dCalle · Oct 30, 2017 at 11:55 AM · librarypreprocessorsymboljit

Get preprocessor symbol UNITY_EDITOR for 3rd party Library

Hey, I'm working on an custom Inspector that fully replaces the original Inspector.

I'm compiling it to a library, because i think not doing that would slow down recompilation. correct me if i'm wrong.

But I'm stuck with yet another problem: I can't use #if UNITY_EDITOR anymore. is there a way to import this symbol and make it part of a JIT compilation?

Or do I have to provide a .cs file that takes care of it outside that library. And How would I do that (a Library Handler)?

I'm confused, overwhelmed and do feel freaking stupid right now... ( next level issues I guess^^)

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Oct 30, 2017 at 01:04 PM

Actually there should never be a reason to use that preprocessor define at all. You generally should seperate runtime and editor code. Editor scripts (and editor assemblies) should be in an editor folder. Also keep in mind that the more recent Unity versions do have special import settings for assemblies which allow you to specify for which platform they are ment for / should be used for. The "editor" is also a platform.


It should be obvious that compiler pre-processor tags can't be used at all since they are only read by the pre-processor which pre-processes your code files before the code is even compiled. So the the actual compiler doesn't see pre processor tags at all. So of course you can't find any traces of those tags in a compiled assembly.


If for some reason you don't want to seperate editor and runtime code (though you should just like Unity itself: UnityEngine.dll and UnityEditor.dll) You would need to compile two versions of your assembly and put both in your project. The "runtime" assembly must be imported to not be used in the editor while the "editor" assembly must only be used on the editor platform. Though such a setup may work for you but i wouldn't recommend to use such an approach when you want to publish it on the asset store.


As i said it's generally a better approach to seperate runtime and editor code. Where / for what do you actually use the tags?

Comment
Add comment · Show 3 · 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 Glurth · Oct 30, 2017 at 06:44 PM 0
Share

"seperate runtime and editor code.. for what do you actually use the tags" [ExecuteInEdit$$anonymous$$ode] $$anonymous$$onoBehaviors? eg. Object.Destroy vs Object.DestroyImmdiate aka "the bane of my existence"

avatar image Bunny83 Glurth · Oct 31, 2017 at 01:03 AM 1
Share

Actually "ExecuteInEdit$$anonymous$$ode" is most likely misused as "editor script". ExecuteInEdit$$anonymous$$ode was never ment to be an editor script but just a way to see the effect of a runtime-script during edit time. So for example a particle effect, a camera moving / aligning script, updating some sort of animation. So the $$anonymous$$onoBehaviour shouldn't contain any editor related stuff in the first place.


As i said editor code should be seperated into it's own assembly or editor folder.

avatar image Glurth Bunny83 · Oct 31, 2017 at 08:43 AM 0
Share

I want to agree; creating and destroying gameobjects should NOT be "editor stuff", but if I don't call UnityEditor.DestoryImmidiate, it pops up a message in the console (at least it used to, haven't tested it in a while... link text Edit: hmm that link seems to have failed... trying again

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

73 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What C# predefines are recognized by Unity? 3 Answers

PreProcessor Directives have suddenly stopped working 0 Answers

How do I use an external library in a Unity script? 2 Answers

RESTful libraries for Unity 6 Answers

How have a script library outside of projects? 1 Answer


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