- Home /
Can custom editors that are built using Reflection.Emit be used in the Unity Editor?
I would like to create an editor class at runtime that is built using Reflection.Emit. In trying to do this I created a new type that inherits from Editor, attaches a CustomEditor attribute, and overrides the OnInspectorGUI method. Unfortunately, it doesn't appear to be working. Is it possible to get Unity to find the created type? I'm wondering if maybe Unity goes through the classes before my code executes and builds the type. Is there anyway to register a new type with Unity or accomplish something equivalent?
Answer by JoshuaMcKenzie · Feb 21, 2016 at 08:44 AM
The UnityEditor namespace isn't availible during runtime. As such you can't use any classes from it in the deployed game, like Editor or AssetDatabase. This is one of the reasons why editor scripts would have their own folder in the Assets folder.
If you are trying to create an interface that the player will use you should use Unity's new UI from 4.6 and classes in the UnityEngine Namespace. Also its usually best that you avoid using Reflection when possible as it carries overhead, and usually the domains that your game will work in won't need Reflection
By runtime, I meant when my code is executed by the Unity Editor (not when the game is running). This wouldn't have any impact on the performance of the game and it's a pretty negligible performance overhead in the Editor (as I mentioned, I have it implemented- Unity just isn't identifying the class).