Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Proper Use of #if UNITY_EDTOR

Discussion in 'Scripting' started by ElroyToscano, Jan 14, 2021.

  1. ElroyToscano

    ElroyToscano

    Joined:
    Jan 8, 2018
    Posts:
    1
    Hello Community,

    I've got a public method in a class to whom I make calls to from the target object of the editor script of the same class. However, I don't want the method to be public as other classes have access to it. So I want it to be specifically public to the editor class of that specific class.
    While researching, I came across #if UNITY_EDITOR as it is made specifically for Editor calls. But while implementing it, inspite of placing the methods inside the #if UNITY_EDITOR those methods are being able to be called from other classes.
    Is there a proper example other than this: https://docs.unity3d.com/Manual/PlatformDependentCompilation.html ?
     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    897
    What you are talking about is Platform Dependent Compilation. You are telling the compiler that, this portion of code will only exist while it is used in a certain platform. A better example will be #if_IOS, which means the portion of code within it will only exist for apple users but no one else. So your code is still accessible because it is being run in the Unity editor.

    So using platform dependent compilation may or may not fit your needs, its impossible to tell without knowing your situation or intentions.
     
    Vryken likes this.
unityunity