Open rgarat opened 7 years ago
I'm confused - do you mean UnityEditor.dll or UnityEngine.dll? I would expect UnityEngine.dll to be available in a player, but not UnityEditor.dll.
Oh, I am sorry, I meant UnityEditor.dll, will edit the issue
Yeah you would only have to look for 2 things, if the file is has Editor
folder in its path, or if it is in a set of UNITY_EDITOR ifdefs. Otherwise anything using UnityEditor;
should be flagged with a warning.
@cmcpasserby It should also check which vs project it is in. Any scripts that have a folder named "Editor" in their filepath will be placed in an "editor only" project, files in that project will not be included when building the project.
Yes, please! I can't count the times I forgot a #IF UNITY_EDITOR and only realized on the next build.
Using types from UnityEditor.dll is an error when not in the Editor assemblys (Assembly-CSharp-Editor, Assembly-CSharp-Edior-firstpass) or using #if UNITY_EDITOR
(or [Conditional("UNITY_EDITOR")]
).
Will it make sense to modify the csproj generation to avoid the UnityEditor references from Assembly-CSharp and Assembly-CSharp-firstpass?
Reasoning behind leaving references to UnityEditor.dll untouched. https://answers.unity.com/questions/770006/why-does-assembly-csharp-reference-unityeditordll.html
There are plenty of reasons for using UnityEditor in runtime code, like validation and updating serialization of ScriptableObjects, but it should always be wrapped in #IF UNITY_EDITOR. This does add the little annoying part that if you generally don't prefer fully qualified references, so usings are automatically added by resharper in the top, you have to wrap the using UnityEditor as well.
Is there a way to make Resharper ignore that rule specifically for UnityEditor, so it prefers to inline the reference qualification when you are in run time code?
It would be actually pretty useful to have a warning when a non IFDEF enclosed reference to anything from UnityEditor was used in a non-editor type. In fact, make that an error, since that is what it is.
Rider would have to understand the new custom assemblies too, since it would have to read them to know when a type in a custom assembly is a editor type or not.
I'm not a fan of the idea of forcing full references, as it would often make lines very long and would make C# look even more verbose than it already is.
Still waiting for this. It`s quite handy and will save a lot of time.
See also RIDER-31718
Just found this issue again though google, just to realize I commented on this over 6 years ago. Is there anything we could do to help get this feature done?
If you use UnityEditor.dll types, in non editor code, everything will compile and run while you are in the editor, but the moment you try to build a player it will play because UnityEditor.dll is not available.
It would be great to get some warning or even error when using UnityEditor.dll types without wrapping those in ifdef UNITY_EDITOR in the regular solution.