Problems to build my project

Hello everyone!

I’m new to game design and programming so forgive me if it’s a very simple question.

When I try to build my project I get 3 error messages in the logs:


This is preventing me from testing the game outside of the editor.

Could someone help me with this

If you have calls to AssetDatabase or other editor code in non-editor-only scripts, you need to wrap them like this:

#if UNITY_EDITOR
  // code here that should only exist in the editor
#endif

In addition, you can make your code do different things if it’s in Play Mode or Edit Mode. So for example…

  void DoStuff()
  {
#if UNITY_EDITOR
    if (Application.isPlaying)
    {
      // code to run if in Play Mode
    } else {
      // code to run if in Edit Mode
    }
#else
    // code to run if in a build
#endif
  }

And you can make it for example do this in WebGL, that in Android or something else otherwise…

#if UNITY_WEBGL
// code when WebGL platform
#elif UNITY_ANDROID
// code when Android platform
#else
// code when Windows, Mac, whatever
#endif

And you can combine stuff like this too:

#if WEBGL && !UNITY_EDITOR
  // stuff when WebGL but NOT in the editor (i.e. only when running in a build in a web browser)
#endif

Finally, any Editor-only scripts should always be placed in /Editor/ folders, i.e. Assets/Whatever/Editor/MyCustomEditor.cs

2 Likes

Are all packages resolved? Have you built the addressables data? These things may be stopping you from building as well as what @adamgolden has mentioned.

Hey @lps27 Like suggested by @adamgolden the Editor Only code was preventing the build.

If you update your project, you should be able to successfully build the project now :wink: