How to set up your CustomEditor scripts to avoid build errors in Unity

Published

Custom editors script are a neat feature in Unity, they allow us to create visual controls for use with our scripts inside the editor such as buttons or foldouts.

Example of a button in the unity editor made from a custom editor script
Sample generation button from our Random Walk article

The issue here is that creating Custom Editor scripts can prevent your game from building.

Unity fails to build if there are scripts using the Editor assembly
Unity fails to build if there are free-standing scripts using the Editor namespace

Thankfully, this is an easy fix provided you’re not already too deep into your project:

  • Make sure to seperate your custom editor logic from your game logic. You just need to put these custom editor scripts in their own files.
  • Create an Editor folder and put your custom editor scripts in it. “Editor” folders are special in Unity, as the engine will know that the files contained inside are only intended to be used within the editor and should not be included at build time.

Once this is done and your custom editor scripts have been put in an Editor folder, your game will now be able to build with no issues!