UNITY_EDITOR define grayed-out code

Just had a funny encounter with Visual studio graying-out everything inside my #if UNITY_EDITOR defines.

Turns out Visual studio must be in Debug mode, not in Release mode, because macros only work for the Debug mode.

Original source:
http://answers.unity.com/answers/668092/view.html

Just found this out from Developer Community


8 Likes

Omg, thank you so much! That helps.

Thanks for the tip!

Also if you don’t see it, there is a chance the Assembly-Csharp reference project was unloaded.
9083848--1257625--upload_2023-6-15_16-26-13.png

in which case just RIGHT click and reload it.
9083848--1257628--upload_2023-6-15_16-26-35.png

1 Like

I know that Visual Studio does not generate a csproj file for package assemblies. I had a similar issue with a module package I was using that was installed from Git that used UNITY_EDITOR defines. Going to Edit > Preferences > Generate csproj files for: git packages and then regenerating the project files seemed to fix the code being greyed out in VS.
9265338--1296633--upload_2023-8-31_23-36-26.png

Your solution was the one i needed, I have no idea why but my Assembly was not loaded on my project