How to make "#if UNITY_EDITOR" automatically unindent all the way to the left?
I'm trying out Rider to see if I'd like to purchase it, and it seems okay so far. But one thing I can't figure out is how to get the preprocessor directive "#if UNITY_EDITOR" and its matching "#endif" to outdent all the way to the left. I found "Preprocessor Directives" in Settings > Editor > Code Style > C#, and tried various settings for "Indent #if, #else, #endit", but nothing worked to FULLY outdent those directives.
This seems like a pretty legit thing to expect. Am I missing something?
Please sign in to leave a comment.
Hello Greg,
Thank you for reporting the issue, I have created a corresponding record on our bug tracker: RIDER-90336. The issue is handled by a dedicated developer there. Please upvote it and click on Watch to monitor the progress of the issue.
Let me know if you have other questions. Have a good day!
Hi, Ivan!
That would not solve the issue. The main problem is that Rider's outdent rule only outdents a single level. So the best you get from the settings is this:
Which gives this on a reformat:
public class Test
{
public void Foo ()
{
#if UNITY_EDITOR
Debug.Log("Foo Called in the editor");
#endif
}
}
What OP is asking for is to have an option to do this:
public class Test
{
public void Foo ()
{
#if UNITY_EDITOR
Debug.Log("Foo Called in the editor");
#endif
}
}
Or as they put it, “unindent all the way to the left?”
This is the common code style in Unity, and is the code style I prefer for #if directives, as it needs to be very visible that the directive is cutting out text, and isn't just a normal control flow block.
I believe Rider used to support this in older versions, but it's not the case in 2023.2.1, which I'm using.
Hello, Bnbuanes ,
Could you please try to set No indent for the #if regions (or any other type of preprocessor directives) in the Settings | Editor | Code Style | C#? It will make the #if-#endif regions aligned all the way to the left. Although, from your example I can't see if you're looking to align these regions at first column, or at the level of the class it's in.