Search Unity

Building AssetBundle from command line, references not recognized

Discussion in 'Editor & General Support' started by IanNicolades, Dec 19, 2018.

  1. IanNicolades

    IanNicolades

    Joined:
    Oct 1, 2016
    Posts:
    40
    I'm trying to build an asset bundle from the command line, and my build script is failing with these errors left in the Unity editor log:

    Code (CSharp):
    1. Assets\CreateAssetBundle.cs(8,13): error CS0246: The type or namespace name 'AssetBundleBuild' could not be found (are you missing a using directive or an assembly reference?)
    2. Assets\CreateAssetBundle.cs(8,47): error CS0246: The type or namespace name 'AssetBundleBuild' could not be found (are you missing a using directive or an assembly reference?)
    3. Assets\CreateAssetBundle.cs(23,13): error CS0103: The name 'BuildPipeline' does not exist in the current context
    4. Assets\CreateAssetBundle.cs(23,73): error CS0103: The name 'BuildAssetBundleOptions' does not exist in the current context
    5. Assets\CreateAssetBundle.cs(23,103): error CS0103: The name 'BuildTarget' does not exist in the current context
    But I am including the correct UnityEditor references, and these errors do not appear when loading the invoked project and inspecting the generated script from the editor in VS, which all appears to be correct:
    Code (CSharp):
    1.  
    2. using UnityEditor;
    3. namespace CAB
    4. {
    5.     public class CreateAssetBundle
    6.     {
    7.         public static void Build()
    8.         {
    9.             AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
    10.             buildMap[0].assetBundleName = "Scripts";
    11.             string[] assets = new string[7];
    12.             assets[0] = @"Assets\Scripts\Simulation\SimScript1";
    13.             <snip>
    14.      
    15.             buildMap[0].assetNames = assets;
    16.             BuildPipeline.BuildAssetBundles("Assets\\Output", buildMap, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
    17.         }
    18.     }
    19. }
    What am I missing here? :p I'm using Unity 2018.3.0b11, following the consensus on how to build asset bundles from this thread and this thread.
     
    danahhan likes this.
  2. IanNicolades

    IanNicolades

    Joined:
    Oct 1, 2016
    Posts:
    40
    Fixed - the problem was that the CreateAssetBundle script needed to be put in an Editor folder. Each asset string also needed to include the filename extension.
     
    yasminewang, danahhan and djalpen24 like this.
  3. aitorolazabal17

    aitorolazabal17

    Joined:
    Nov 27, 2023
    Posts:
    31
    I'm having this problem in unity 2021.3.22f1, while running the script from command line. I have the script in Assets\Editor and this is the code
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class CreateAssetBundles : MonoBehaviour
    5. {
    6.     public static void BuildAllAssetBundles()
    7.     {
    8.         AssetBundleBuild[] bundleBuild = new AssetBundleBuild[1];
    9.         bundleBuild[0].assetBundleName = "bundlename";
    10.  
    11.         string[] bundleassets = new string[1];
    12.         bundleassets[0] = @"Assets\Object\barril.fbx";
    13.        
    14.  
    15.         bundleBuild[0].assetNames = bundleassets;
    16.  
    17.         BuildPipeline.BuildAssetBundles("Assets\\ABs", bundleBuild, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
    18.     }
    19. }
    so the asset has the .fbx extension. What am I missing?
     
  4. aitorolazabal17

    aitorolazabal17

    Joined:
    Nov 27, 2023
    Posts:
    31
    I deleted my assembly reference file (that I was not using) and the error disappeared