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. Dismiss Notice

Question Can't build a game through UnityEditor (error)

Discussion in 'Editor & General Support' started by masternully, Dec 4, 2022.

  1. masternully

    masternully

    Joined:
    Dec 22, 2018
    Posts:
    13
    This is my code:
    Code (CSharp):
    1.  
    2.     public static BuildTarget TargetPlatform = BuildTarget.StandaloneWindows;
    3.     public static BuildOptions BuildOptions = BuildOptions.Development;
    4.  
    5. [MenuItem("Tools/Msf/Build Master + Spawner", false, 11)]
    6. public static void BuildMasterAndSpawner(string path)
    7.     {
    8.         var masterScenes = new[]
    9.         {
    10.             QuickSetupRoot+ "/Scenes/SampleScene.unity"
    11.         };
    12.  
    13.         BuildPipeline.BuildPlayer(masterScenes, path + "/SampleScene.exe", TargetPlatform, BuildOptions);
    14.     }
    And this is errors when I try to build:

    Code (CSharp):
    1. Assets\Scripts\MsfQuickBuild.cs(16,19): error CS0246: The type or namespace name 'BuildTarget' could not be found (are you missing a using directive or an assembly reference?)
    2. Assets\Scripts\MsfQuickBuild.cs(22,19): error CS0246: The type or namespace name 'BuildOptions' could not be found (are you missing a using directive or an assembly reference?)
    3. Assets\Scripts\MsfQuickBuild.cs(26,6): error CS0246: The type or namespace name 'MenuItemAttribute' could not be found (are you missing a using directive or an assembly reference?)
    4. Assets\Scripts\MsfQuickBuild.cs(84,6): error CS0246: The type or namespace name 'MenuItem' could not be found (are you missing a using directive or an assembly reference?)
     
  2. masternully

    masternully

    Joined:
    Dec 22, 2018
    Posts:
    13
    You have to put your script inside your "Editor" folder. "Assets/Editor/AudioSourceReplacement.cs" should do the trick.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Yes, this. 99% of build-y-ish scripts should go in an Editor/ folder.

    Another way if only a tiny part of something is editor only is to guard it with
    #if UNITY_EDITOR
    so that all parts of it "drop out" when you build.

    https://docs.unity3d.com/Manual/PlatformDependentCompilation.html