Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Build script cannot find "MenuItem"

Discussion in 'Editor & General Support' started by H0lger, Jun 13, 2018.

  1. H0lger

    H0lger

    Joined:
    Apr 28, 2017
    Posts:
    2
    I tried to do a setup script for my builds. The menu item gets displayed. As soon as I click on the Item, it is fetching some results for my platform but then crashes with errors like:

    Code (CSharp):
    1. Assets/Scripts/ProjectBuilder.cs(8,6): error CS0246: The type or namespace name `MenuItem' could not be found. Are you missing an assembly reference?
    2.  
    3. Assets/Scripts/ProjectBuilder.cs(11,9): error CS0246: The type or namespace name `BuildPlayerOptions' could not be found. Are you missing an assembly reference?
    4.  
    5. Assets/Scripts/ProjectBuilder.cs(12,9): error CS0841: A local variable `buildPlayerOptions' cannot be used before it is declared
    6.  
    7. Assets/Scripts/ProjectBuilder.cs(14,9): error CS0103: The name `BuildPipeline' does not exist in the current context
    8.  
    I do not know why it is unable to find those classes after clicking that menu item. I am using Unity 2018.1.2f1 . See below the complete build script. It is basically copied from https://docs.unity3d.com/ScriptReference/BuildPipeline.BuildPlayer.html (Or also https://docs.unity3d.com/Manual/BuildPlayerPipeline.html)

    Code (CSharp):
    1.  
    2. using UnityEditor;
    3. using System.Diagnostics;
    4. public class ProjectBuilder {
    5.     [MenuItem("CustomScripts/Build Android")]
    6.     public static void BuildAndroid()
    7.     {
    8.         BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
    9.         buildPlayerOptions.scenes = new[] { "Assets/MainScene.unity" };
    10.         buildPlayerOptions.locationPathName = "builds/AndroidBuild";
    11.         buildPlayerOptions.target = BuildTarget.Android;
    12.         buildPlayerOptions.options = BuildOptions.None;
    13.         BuildPipeline.BuildPlayer(buildPlayerOptions);
    14.     }
    15. }
    16.  
    Does anyone know what is going wrong? Seems to be a beginners mistake somekind of..
     
    Last edited: Jun 13, 2018
  2. H0lger

    H0lger

    Joined:
    Apr 28, 2017
    Posts:
    2
    That was a beginners question indeed. If you get those errors you have to put the script inside the editor folder. "Assets/Editor/ProjectBuilder.cs" did the trick.
     
  3. jlapine_scott

    jlapine_scott

    Joined:
    Jun 6, 2018
    Posts:
    1
    Thanks for posting the answer.
     
  4. DiegoCN

    DiegoCN

    Joined:
    Jul 16, 2018
    Posts:
    1
    Thanks for the answer.
     
  5. richard-frank-movile

    richard-frank-movile

    Joined:
    Aug 30, 2018
    Posts:
    1
    Wow! Its extremely useful! Thx so much!
     
  6. YoyoMario

    YoyoMario

    Joined:
    Apr 8, 2013
    Posts:
    15
    Thanks!
     
  7. Ukins

    Ukins

    Joined:
    Oct 5, 2018
    Posts:
    2
    Thanks a lot
     
  8. SVorgs

    SVorgs

    Joined:
    Sep 30, 2016
    Posts:
    1
    Thanks a lot
     
  9. kmithun9

    kmithun9

    Joined:
    May 13, 2019
    Posts:
    5
    Thanks :)
     
  10. mrmeizongo

    mrmeizongo

    Joined:
    Mar 2, 2018
    Posts:
    2
    Thank you.
     
  11. suryavj

    suryavj

    Joined:
    Dec 5, 2018
    Posts:
    2
    BUt i got the same error even i put y script in editor folder
     
    Tubestorm likes this.
  12. Tubestorm

    Tubestorm

    Joined:
    May 8, 2020
    Posts:
    6
    were you able to fix this problem.
     
  13. jubaerjams8548

    jubaerjams8548

    Joined:
    Jun 8, 2020
    Posts:
    33
    if the same thing happens then click on that error and then automatically a file will be marked in 'Project" TAB and delete that file and build your project again. that worked for me
     
  14. Baylamon

    Baylamon

    Joined:
    May 16, 2019
    Posts:
    13
    For my project I had to use Assets/Scripts/Editor.
    Maybe since I have all scripts in Assets/Scripts.
     
    john10mwangi likes this.
  15. RohitNutalapati

    RohitNutalapati

    Joined:
    May 17, 2017
    Posts:
    2
    Skull55_55 likes this.
  16. maurofuentes

    maurofuentes

    Joined:
    Apr 5, 2018
    Posts:
    8
    Thank you all!
     
  17. aziz728

    aziz728

    Joined:
    Feb 2, 2021
    Posts:
    1
    Thank you very much
     
  18. Balddog123

    Balddog123

    Joined:
    May 23, 2018
    Posts:
    4
    amazing how the actions of one person can change the lives of so many. Thanks for the solution!
     
  19. deft1991

    deft1991

    Joined:
    Nov 15, 2020
    Posts:
    1
    That you so much!!!!!!
     
  20. Piotrone

    Piotrone

    Joined:
    Mar 6, 2015
    Posts:
    36
    So helpful! Thank you!
     
  21. tokar_dev

    tokar_dev

    Joined:
    Feb 1, 2017
    Posts:
    9
    I faced with build-compile errors where editor-assembly was setup incorrectly.
    In case if you have editor-assembly check `Editor` checkbox in `Platforms` section.