Assembly Definition Assets missing use case...

Hello all !! :slight_smile:
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? :slight_smile:
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 !! :slight_smile:
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 !!! :stuck_out_tongue:

The only workaround that I was able to use is to keep only 1 Assembly Definition Asset AND put an #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 :slight_smile: ) 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 !! :slight_smile:

You can use [assembly: InternalsVisibleTo(“MyPlugin.Editor”)] inside your MyPlugin assembly. This should make the internal singleton accessible to your editor scripts

1 Like

That worked !!! I’m happy now !! :slight_smile:
Thanks for the help.

Small test project attached so you can check the full story if interested.

Cheers :slight_smile:

6170908–675331–AssemblyDefinitionAssetInternalClassesIssue.7z (14.1 KB)

1 Like

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