- Home /
Why does Assembly-CSharp reference UnityEditor.dll
When adding editor scripts to the project, the generated C# project will reference UnityEditor.dll and the Assembly-CSharp.dll (editor code has access to the unity editor and to all "runtime" game code).
I've just realized now that the generated project Assembly-CSharp is automatically set to reference UnityEditor.dll as well.
What is the logic behind this ? runtime code cannot use any editor features. Is this solely for the purpose of running it in the editor ? If so, why not create that code in Editor folders ?
Great question. I wondered that too myself. Never looked into it so much though, I think they remove the reference when you build. $$anonymous$$y guess is that they made it available from your runtime assemblies to make things easier on you? - a lot of the times I find it convenient and less of a bother to include some editor code (like Handles for instance) and wrap it up with #if UNITY_EDITOR. $$anonymous$$aybe there are other reasons.
Hey there,
This lets you have a script in a non-Editor folder but still have access to Editor functions. This works just like Vexe was saying if you want Editor functions in runtime, then you can by defining them out. If you forget to do that your project will fail to build when Unity removes the reference. I would also not be surprised if this had to do with internal Unity stuff.
I had a lot of occurrences where I wanted to have such a functionality available to my editor classes. i.e. write editor scripts, put them in an Editor folder and be able to access them somehow from runtime scripts just like UnityEditor. Never gave it too much thought nor effort, but it would be nice.