I have several EditorWindow and Editor scripts within Editor folders, and when I build AssetBundles for mobile platforms (eg iOS), these scripts Editor scripts throw errors for symbols they’re referencing within non-Editor scripts - which are all within #if UNITY_EDITOR blocks.
It seems very strange to me that AssetBundle builds, while set to iOS or Android, will not build #if UNITY_EDITOR code within modules not residing within Editor folders, but it WILL build modules within Editor folders. Furthermore, this code, which is “Editor Only” for utilities and other functions is completely unrelated and unnecessary for building AssetBundles.
Am I missing something? How do I hide both from AssetBundle builds or expose #if UNITY_EDITOR code to the AssetBundle build? Btw, I tried wrapping my scripts in Editor folders in #if UNITY_EDITOR blocks, but this didn’t change anything.
Followup Edit -
I commented out all references in modules residing in Editor folders to non Editor modules and I was able to build AssetBundles successfully for mobile.
So it seems there’s some problem in AssetBundle builds with Editor scripts referencing #if UNITY_EDITOR code blocks in non-Editor scripts.
Followup Edit 2 -
So I’ve narrowed down the offending situation. I’ve illustrated this in pseudo code below (in C#).
File in Assets/Editor
#include UnityEditor;
[CustomEditor(typeof(MyClass))]
public class MyClassEditor : Editor
{
public override void OnInspectorGUI()
{
MyClass.InternalMethodOne(); // this is ok, since its declaration is outside #if block
MyClass.InternalMethodTwo(); // this throws an unknown definition compile error
}
}
File in Assets/Scripts – will throw compile errors when building AssetBundles for mobile since function symbol declarations are inside an inactive conditional compilation block
#include UnityEngine;
public class MyClass : Monobehaviour
{
public void InternalMethodOne()
{
}
#if UNITY_EDITOR
public void InternalMethodTwo()
{
}
public void InternalMethodTwo()
{
}
public void InternalMethodThree()
{
}
public void InternalMethodFour()
{
}
#endif
}
To fix this, we have to do the following instead:
public class MyClass : Monobehaviour
{
public void InternalMethodOne()
{
}
public void InternalMethodTwo()
{
#if UNITY_EDITOR
#endif
}
public void InternalMethodTwo()
{
#if UNITY_EDITOR
#endif
}
public void InternalMethodThree()
{
#if UNITY_EDITOR
#endif
}
public void InternalMethodFour()
{
#if UNITY_EDITOR
#endif
}
}
This is slightly more annoying and I’d say less than Ideal since we’re forced to build stub symbol definitions into production code. I think Unity should be able to address this issue.