So I have a runtime MonoBehavior IN A PLUGIN that wants to see if a certain editor helper MonoBehavior is available FROM ANOTHER PLUGIN. It’s only available in the editor.
The solution was this
object o = m_gameObject.AddComponent("MyEditorOnlyClass");
if (o != null) {
m_gameObject.SendMessage("InitEditorOnlyClass", this);
}
But now adding a component by name is deprecated. I can’t use gameObject.AddComponent
because it will fail to compile when not in the editor and the editor only class will also fail to compile for runtime only code (it accesses UnityEditor stuff).
So what’s the suggested workaround now that I’m not allowed to do this anymore?
The part about IN A PLUGIN means the code is in DLL so using #if UNITY_EDITOR
won’t help because the code has already been compiled. MyEditorOnlyClass
is in a DLL sitting in Plugins/Editor. The usage of MyEditorOnlyClass
is in a DLL sitting in Plugins.