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

1
8 comments

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_EDITOR

It 99% reason why our CI builds fail. Someone forgot to add this simple line.

0

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.

0

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:

#if UNITY_EDITOR
#endif

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

0

You should be able to change it in the bottom of the editor:

1

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.

-1

When using Assembly-CSharp-player context, Rider still analyse the wrong path and report errors

0

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. 

0

Please sign in to leave a comment.