Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Implement interface only #if UNITY_EDITOR

Discussion in 'Editor & General Support' started by Vifi, Jan 26, 2022.

  1. Vifi

    Vifi

    Joined:
    Aug 5, 2013
    Posts:
    28
    Hi,
    i have this problem... i write an tool that will be placed as package and obtain from package manager. This tool needs to get some varibles from script within project. Till now i just needed to find it so i used class attribute, but now i need to obtain some information from it... i planned to do this by interface declared in package and used in project script but there is one more constrain. I need it to be only UNITY_EDITOR thing... in other words i want to implement that interface only if it is in UNITY_EDITOR, otherwise not (because probably build will fail)
    Do you know any solution to my problem?
    Thanks in advance and cheers
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    8,792
    This more than likely will mess up any form of serialization. I wouldn't even think about it. Always prefer the separation of Editor and Runtime code, as much as possible.
    Why would the build fail just because you implement an interface? What interface are we talking about?

    Could you show some code, what do you mean?
     
  3. Vifi

    Vifi

    Joined:
    Aug 5, 2013
    Posts:
    28
    Sadly i cannot share any code, but your answer lead me to solve my problem. Thank you very much!
     
    Lurking-Ninja likes this.