Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Asset Bundle support?

Discussion in 'Unity Build Automation' started by steve.salmond, Sep 17, 2014.

  1. steve.salmond

    steve.salmond

    Joined:
    Jan 29, 2013
    Posts:
    8
    Hi guys, wondering if it's currently possible to produce asset bundles via Cloud Build. If not, is this something on the roadmap?

    I think the most flexible solution might be to allow command line parameters to be specified. Then we could specify an executeMethod parameter to call into custom build logic that would in turn invoke BuildPipeline.BuildAssetBundle().

    Not sure how you'd get the bundle files out from the build, though. Perhaps you could have something like Shippable's build artifact folder that gets zipped up automatically and made available for download. That way we could also do things like spit out unit test results, code coverage reports, or whatever.

    I guess we could set up a Jenkins server to do this stuff, but Cloud Build seems way cooler.. :)

    Cheers!
     
    hypeNate likes this.
  2. hypeNate

    hypeNate

    Unity Technologies

    Joined:
    Apr 4, 2014
    Posts:
    272
    @steve.salmond - yes, Asset Bundles are on our roadmap. We don't have a date for when that will be ready, but it's something we plan on doing.

    For those of you who are interested in using Asset Bundles and find this discussion thread - please post any thoughts or ideas you might have for this feature request - thanks!
     
  3. steve.salmond

    steve.salmond

    Joined:
    Jan 29, 2013
    Posts:
    8
    Thanks for the quick response!

    The command line parameters idea is just one possibility I guess - you could also have a more specialized workflow that focuses just on bundle production. The latter would probably be more user friendly if it existed, assuming there was a convenient way to specify what content went into the bundle (perhaps specifying a folder and/or set of file extensions?), and a way to get at those bundles once they were built, or a way to deploy bundles directly (e.g. push to S3).

    Looking forward to hearing how this develops. I'm sure you guys have a mighty big shopping list already, so no pressure.. :)
     
    hypeNate likes this.
  4. FlolF

    FlolF

    Joined:
    Nov 20, 2012
    Posts:
    14
    Hi there, I'm also interested in producing asset bundles via unity cloud. How is it going with this feature?
    Best, Flo
     
  5. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    745
    No updates yet. But you can write your own pre/post build scripts which generate the Asset Bundles for you and upload the output to a external storage.
     
    evertoon.hostmaster likes this.
  6. Fasox

    Fasox

    Joined:
    Aug 8, 2012
    Posts:
    7
    I was wondering if this could be used to produce AssetBundles at runtime in a future...
     
  7. BrianND

    BrianND

    Joined:
    May 14, 2015
    Posts:
    82
    I've tried building asset bundles in the pre and post export cloud methods but my build times out if it takes too long. Is there a way around this?
     
  8. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    I'd be interested in this too. What would the process be for using Pre-Post in cloud build for Asset Bundles?
     
  9. gbabic

    gbabic

    Joined:
    May 10, 2013
    Posts:
    2
    @hypeNate definitely interested in this feature.

    Currently we have a custom editor window for performing asset bundle builds. It would be nice to see this feature integrated into the IDE by default. Even if it's just a basic select output directory and build currently active platform button.

    A CLI would also be quite handy if we wanted to create our own AssetBundle CI build. But offloading this task to you guys would be well worth the money. Is Unity willing to host the bundles also for development purposes? Or perhaps will we be required to supply ftp details or similar?

    Very excited to see what you guys come up with!
     
  10. kelloh

    kelloh

    Joined:
    Mar 2, 2015
    Posts:
    29
    For the record, I'm also interested in building Asset Bundles manually, without Unity. It would open up the possibility of constructing custom AssetBundles by, say, a server, for game clients to stream.
     
  11. opponent019

    opponent019

    Joined:
    Feb 6, 2014
    Posts:
    28
    Any news about this?
    Also, a bit off topic but still related: any plans for being able to import FBX/OBJ (without them being in an AssetBundle) during runtime without the need of a third party plugin?
     
  12. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Hello I need to Build AssetBundles and include it in StreamingAssets folder to load HD/SD variant at runtime.

    I only need to add a pre script build but I do not find how to do this. I know how to launch build and script before it with a menu entry. But UnityCloud build will not launch it.
     
  13. narayanb

    narayanb

    Joined:
    Oct 4, 2015
    Posts:
    1
    Its been nearly 3 years since that original post. Is this something that may happen with Cloud builds anytime? I am also wondering if there are alternates to doing this outside the editor (like the command line options mentioned). Our app uses a lot of dynamic content that needs to be added this way to be downloaded in the app. Right now, the need for doing this using the editor makes the process cumbersome for us.
     
  14. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    Hello @narayanb . I have found how to do and build AssetBundles in UCB and upload them to my server automatically. Really save my time.
     
  15. sun_t89

    sun_t89

    Joined:
    Jul 4, 2017
    Posts:
    1
    How to do it? I am also seeking for soulution to build assetbundle automatically.
     
  16. TobyKaos

    TobyKaos

    Joined:
    Mar 4, 2015
    Posts:
    214
    For instance I have an empty project with all my sprites (mercenaries and weapons). I assigned asset bundles and variants.

    Create a main unity scene empty.
    A prebuild script create AB like this:

    Code (CSharp):
    1. // Build specific target
    2.     static void Build(BuildTarget target, string path)
    3.     {
    4.  
    5.         TestVersion();
    6.  
    7.      
    8.  
    9.         Debug.Log("Build Asset Bundles");
    10.         BuildPipeline.BuildAssetBundles(path,
    11.                                         BuildAssetBundleOptions.None,
    12.                                         target);
    13.  
    14.         CopyAssetBundlesToStreamingAsset();
    15.  
    16.  
    17.      
    18.     }
    I have a preproc define to enable only right Build method like this:
    Code (CSharp):
    1.  
    2. #if UNITY_ANDROID
    3.         [MenuItem("Resources/AssetsBundles/Build Asset Bundles/Android")]
    4.         public static void BuildAssetBundles()
    5.         {
    6.             Build(BuildTarget.Android, "AssetBundles/Android");
    7.         }
    8. #endif
    Then AB is deleted and copyied in StreamingAssets in my Main game project. In my other project that manage mercenaries and weapons I upload to server in post buid script.

    Add post build editor script in UCB that create AB and upload to my server with UnityWebRequest (or HttpWebRequest because depends of your server sometimes one work or the other).

    sample code to put to AmazonS3 (read the doc on Amazon if needed)

    Code (CSharp):
    1. Debug.Log("send to amazons3");
    2.                 request = (HttpWebRequest)WebRequest.Create(amazonS3SignedUrl);
    3.                 request.Method = "PUT";
    4.                 //request.ServicePoint.Expect100Continue = false;
    5.                 request.ProtocolVersion = HttpVersion.Version10;
    6.                 request.ReadWriteTimeout = 500000;
    7.                 request.Timeout = 500000;
    8.  
    9.                 string filePath = "AssetBundles/"+plateforme+"/" + Pair.Key;
    10.                 using (Stream dataStream = request.GetRequestStream())
    11.                 {
    12.                  
    13.                     // envoie en streaming
    14.                     byte[] buffer = new byte[8000];
    15.                     using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
    16.                     {
    17.                         int bytesRead = 0;
    18.                         long totalRead = 0;
    19.  
    20.                         while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) > 0)
    21.                         {
    22.                             dataStream.Write(buffer, 0, bytesRead);
    23.  
    24. #if !UNITY_CLOUD_BUILD
    25.                             totalRead += bytesRead;
    26.                             EditorUtility.DisplayProgressBar("Uploading Asset Bundles", "Reading Asset " + Pair.Key, (float)totalRead / (float)fileStream.Length);
    27. #endif
    28.                         }
    29.                     }
    30.  
    31.  
    32.                 }
    33.  
    34. #if !UNITY_CLOUD_BUILD
    35.  
    36.                 EditorUtility.DisplayProgressBar("Uploading Asset Bundles", "Uploading Asset " + Pair.Key, progress / nbBundles);
    37. #endif
    38.                 httpResponse = request.GetResponse() as HttpWebResponse;
    39.  
    40.                 Debug.Log(httpResponse.ToString());
    41.                 httpResponse.Close();

    Maybe you need certificate callback for https:

    Code (CSharp):
    1. public static bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    2.     {
    3.         bool isOk = true;
    4.         // If there are errors in the certificate chain, look at each error to determine the cause.
    5.         if (sslPolicyErrors != SslPolicyErrors.None)
    6.         {
    7.             for (int i = 0; i < chain.ChainStatus.Length; i++)
    8.             {
    9.                 if (chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown)
    10.                 {
    11.                     chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
    12.                     chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
    13.                     chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
    14.                     chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
    15.                     bool chainIsValid = chain.Build((X509Certificate2)certificate);
    16.                     if (!chainIsValid)
    17.                     {
    18.                         isOk = false;
    19.                     }
    20.                 }
    21.             }
    22.         }
    23.         return isOk;
    24.     }
    25.  
    26.  
    27.  
    28.  
    29.  
    30.  
    31.  
    32. //set callback for HTTPS
    33.         ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;

    This is a good starting point. You need to have a server URL where to sent AB. Before PUT I POST on a server to obtain a signed Amazon URL.

    Hope you will manage to create a great pipeline for AB and UCB. This saved my life and hours of build.