Search Unity

Question UNITY_EDITOR in package

Discussion in 'Scripting' started by Puschie, Jun 4, 2020.

  1. Puschie

    Puschie

    Joined:
    Feb 16, 2013
    Posts:
    7
    Hi,
    we use UNITY_EDITOR to exclude debug code from production build and we use packages to easily share modules and stuff - after moving some functionality to a package, we found the problem that the UNITY_EDITOR branch is always inactive.

    i know that this is not the best solution ( using editor code in non editor classes ) but it should be valid as far as i know
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I haven't done this myself so I can't give specific guidance, but I'm guessing that you can do this by setting up the defines in your ASMDEF file for your package?

    It does seem like a Unity bug, though, that this doesn't work out of the box.
     
  4. Are you sure about this?
    Because I got curious and the first file I opened (Timeline package/Runtime/AnimationPreviewUtilities.cs) basically entirely in UNITY_EDITOR mode.
    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4.  
    5.  
    6. namespace UnityEngine.Timeline
    7. {
    8.     static class AnimationPreviewUtilities [...]
    (the #endif is at the end of the file)
     
  5. Puschie

    Puschie

    Joined:
    Feb 16, 2013
    Posts:
    7
    thanks for your suggestions - didnt find a way to achieve this with asmdef
    @Lurking-Ninja
    have checked that file but couldnt debug it, looks exactly the same like the unity_editor parts in my package.
    im not sure if its a debug problem, maybe some weird configs that have side effects - will check if its something debugger related, but all public properties of the monobehaviour we have surrounded by unity_editor are not visible in the editor and are not accessible by the class them self so it might be something compiling related

    For now implemented a workaround - watcher class with callback events to store data outside of runtime package.
    The smart solution would be a IoC framework to use injection and inception but thats different style of development ( and not easy possible in unity )

    Currently we use Unity 2020.1.0b11 but found the problem while working with Unity 2019.2.11f1