#if UNITY_EDITOR in .dll

I’m making custom editor, where i have editor scripts and normal scripts (monobehaviours) so i decided to create the entire editor (editor and normal scripts) into a dll.
I have a solution where i have one dll for editor scripts and another one for the normal scripts.
My problem is, the normal scripts use UnityEditor classes like EditorApplication or Selection, so i thought “Ok, i will put them under #if UNITY_EDITOR flag so when i build it will not see that code”. The problem is that when i compile the dll it will not understand what is UNITY_EDITOR flag so its like doesn’t exist and my editor parts in the normal scripts are not working :confused:

Is there any hack or trick or am i doing something wrong? Or am i just limited?

Thanks!

Since you’re building the DLL yourself, it’s up to you to define the preprocessor variables you require. This is what Unity does automatically based on the current project settings, platform and whether you’re building for standalone or for the editor. Don’t forget, Unity is just reading in your DLL and doesn’t know anything about the compiled code beyond any debug symbols you may have generated.

You can create additional configurations inside Visual Studio to produce different output DLLs based on whatever settings you need: e.g. as well as Debug and Release you could have EditorDebug and EditorRelease.

On the plus side this means you have even more flexibility: you can build a “diagnostic” version of your DLL that has extra debug features turned on, and a “redistributable” version that has extra optimizations or whole features disabled.