Project does not build. Build exists with using PropertyDrawer, but it plays fine in editor.

Hello all!

I have been working on my scene for a couple of weeks and I have updated my unity version to 2018.1. All the scripts where working properly until.
After upgrade my project plays fine in the editor but when trying to build I get errors about

Assets/Scripts/“Myscript” error CS0246 “SerializedProperty” and “PropertyDrawer” could not be found.

Then it got me thinking maybe it is a bug, so I have followed the project example at PropertyDrawer reference page : Unity - Scripting API: PropertyDrawer same errors i get when I am trying to build with this script. It was fine with 2018 beta until I upgraded. Could this be a bug?

It’s not a bug, those classes exists in UnityEditor.dll which is only available in Editor context, and cannot be used by the player.

Try wrapping the code involved around with #if UNITY_EDITOR / #endif, or move that script to Assets/Editor folder

Alternately, put that code into a directory named “Editor” and it will be excluded from the build. All of my Editor and PropertyDrawer classes go into an Editor directory in my project.

…and how does one go about this?

Didn’t both of the preceding posts explicitly answer that question?

Moving all the editor-related code into ‘Editor’ folder solved this issue for me

Thanks a lot. It worked for me