Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Feedback Assembly Definition Assets missing use case...

Discussion in 'Editor & General Support' started by Eugenio, Mar 26, 2020.

  1. Eugenio


    Mar 21, 2013
    Hello all !! :)
    So, today I was trying to do some generic plugins that I could use across different projects and I ended up encountering a very specific issue.
    The use case is the following:
    • I have a public static class with public static methods
    • the public static class internally instantiates and uses a singleton instance of a MonoBehaviour defined as internal (I don't want anyone to be able to publicly mess around with it)
    • for debugging reasons, the internal MonoBehaviour instance is NOT hidden in the Inspector but it cannot be modified (proper flags have been applied to it)
    • the internal MonoBehaviour has a custom inspector script that implement some debug features: you can see the internal status of what's happening BUT you cannot interact with this "report"
    • all the scripts are inside a Scripts subfolder contained into the plugin main folder
    • all the editor related scripts are inside an Editor subfolder contained in the Scripts subfolder located in the plugin main folder
    • the Assembly Definition Asset is contained in the main folder of the plugin

    Now... did you guess already my problem? :)
    This approach will not work because when a build is triggered, Unity will generate a compiler error: the scripts inside the Editor folder, obviously, are included also in the runtime because of the Assembly Definition Asset presence.

    The right approach would be to create 2 subfolders in the Scripts one: one for runtime scripts and one for editor scripts. After this, to move the original Assembly Definition Asset in the runtime folder and to create a new one in the editor folder that it will be only included in the editor platform.
    Awesome !! :)
    But it doesn't work in my case: seen that the MonoBehaviour has been defined as internal, the custom editor script cannot access it because it resides in a separate assembly !!!

    Without an Assembly Definition Assets and introducing the usage of editor folders, all works because of Unity's internal voodoo !!! :p

    The only workaround that I was able to use is to keep only 1 Assembly Definition Asset AND put an
    Code (CSharp):
    1. #if UNITY_EDITOR
    preprocessor word in those files that should be used only in editor.

    Obviously I don't like this solution !!

    So... either I'm not really able to use the great Assembly Definition Asset tool that Unity gave us and you will teach me how to solve my problem (thank you very much :) ) OR I would like to kindly ask Unity Technologies to see if there is something they can do to ease-in this use case into the Assemble Definition Asset system.

    Many many thanks for your interest in my post !! :)
    Last edited: Mar 26, 2020
  2. msfredb7


    Nov 1, 2012
    karl_jones likes this.
  3. Eugenio


    Mar 21, 2013

    Attached Files:

    MostHated likes this.
  4. MostHated


    Nov 29, 2015
    Thanks for sharing this. Being able to see a working copy in action quickly helped me realize what I was doing wrong.