Search Unity

Problems to build my project

Discussion in 'Open Projects' started by lps27, Jun 13, 2021.

  1. lps27

    lps27

    Joined:
    Jun 11, 2021
    Posts:
    1
    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:

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

    Could someone help me with this
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    If you have calls to AssetDatabase or other editor code in non-editor-only scripts, you need to wrap them like this:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.   // code here that should only exist in the editor
    3. #endif
    In addition, you can make your code do different things if it's in Play Mode or Edit Mode. So for example..
    Code (CSharp):
    1.   void DoStuff()
    2.   {
    3. #if UNITY_EDITOR
    4.     if (Application.isPlaying)
    5.     {
    6.       // code to run if in Play Mode
    7.     } else {
    8.       // code to run if in Edit Mode
    9.     }
    10. #else
    11.     // code to run if in a build
    12. #endif
    13.   }
    And you can make it for example do this in WebGL, that in Android or something else otherwise..
    Code (CSharp):
    1. #if UNITY_WEBGL
    2. // code when WebGL platform
    3. #elif UNITY_ANDROID
    4. // code when Android platform
    5. #else
    6. // code when Windows, Mac, whatever
    7. #endif
    And you can combine stuff like this too:
    Code (CSharp):
    1. #if WEBGL && !UNITY_EDITOR
    2.   // stuff when WebGL but NOT in the editor (i.e. only when running in a build in a web browser)
    3. #endif
    Finally, any Editor-only scripts should always be placed in /Editor/ folders, i.e. Assets/Whatever/Editor/MyCustomEditor.cs
     
    ChemaDmk and Smurjo like this.
  3. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Are all packages resolved? Have you built the addressables data? These things may be stopping you from building as well as what @polemical has mentioned.
     
  4. ChemaDmk

    ChemaDmk

    Unity Technologies

    Joined:
    Jan 14, 2020
    Posts:
    65
    Hey @lps27 Like suggested by @polemical the Editor Only code was preventing the build.
    If you update your project, you should be able to successfully build the project now ;)