Unity Auto Build Fix - #ifdef UNITY_EDITOR for using UnityEditor
Answered
When working with Rider and Unity it happens quite often that Rider includes using statements like UnityEditor or similar. It would be nice if Rider would automatically wrap statements including UnityEditor in an #ifdef condition
Please sign in to leave a comment.
Yes. It doesn't make sense not to do it. Additionally, issue warning for using any editor package code in normal classes (outside Editor folder) that this needs to be wrapped in
#if UNITY_EDITORIt 99% reason why our CI builds fail. Someone forgot to add this simple line.
To be fair: since i wrote this Rider introduced player projects which can enabled in Unity project settings. They display errors in cases of editor code being used in runtime classes.
https://docs.unity3d.com/Packages/com.unity.ide.rider@2.0/manual/using-the-jetbrains-rider-editor-package.html
Ok, I tested this it's a different use case. It doesn't allow you to use Editor classes at all, like they are not added to solution dependencies. So you have to blindly write code inside:
I want to be able to use editor classes inside mono behaviors intended for player. I would like to wrap them automatically in #if #endif
You should be able to change it in the bottom of the editor:
Hi all,
we think that implementing of automatically wrapping is not a good idea because it complicates code analysis and makes code cluttered, worsens its readability. Using players project option is preferred way for being able to see errors in IDE.
When using Assembly-CSharp-player context, Rider still analyse the wrong path and report errors
Noemi, is it possible to share a sample project that we could use to check the issue on our side and having a closer look at it? It will also help if you can add more information on your environment, like Rider version, Unity version, OS.