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

Using a custom build script to make assetbundles for web

Discussion in 'Unity Build Automation' started by taxfromdk, Jul 11, 2015.

  1. taxfromdk

    taxfromdk

    Joined:
    Oct 30, 2009
    Posts:
    95
    Hi Guys,

    I am working on a project I would like to put into the cloud build system. My problem though is that it uses its own custom build script.

    My targets are IOS and Webbuild, and in the future WebGL.

    The web build use assetbundles so I will need some way of creating these.

    I know people have been talking about you can write post and pre scripts to be run in conjunction with the build process, but I can find no examples of this as well as the debugging process of building such a script.

    Ideally I would have the buildprocess make all my assetbundles and upload them via FTP to our staging server.

    Any inputs are highly appreciated.

    Kind regards

    Jesper
     
  2. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    740
    Yes, that's totally possible. I would suggest to use post process attributes to upload a single file to your server. You can use a node.js local server or something similar to output any logs related to connection with your webserver if you can not monitor the remote location. Once the single file upload works, it should be possible to trigger the Asset Bundle build pipeline and upload the finished files afterwards :cool:
     
  3. taxfromdk

    taxfromdk

    Joined:
    Oct 30, 2009
    Posts:
    95
    Hi David,

    Thanx for your answer. I have now played around with the [PostProcessBuild] flag and I can run code after build.

    Two questions arise though.

    1) Does there exist a hook for running before, where I can react to what platform is being built for. I have a build for IOS where all scenes are included and a build for web where scenes are put in assetbundles.

    2) How do I communicate with the outside world? I have tried creating a www object but I cant use a yield as it happens in Editor script.

    Kind regards

    Jesper
     
  4. taxfromdk

    taxfromdk

    Joined:
    Oct 30, 2009
    Posts:
    95
  5. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    740
    1.) There is a pre-process build method too, it's available in the Studio Plan. But you can preprocessor defines to use different commands on different platforms, it that's what you need.
    2.) You should be able to reach your server from within your pre/post C# methods. Could you maybe post your code so we can help to improve it?
     
  6. taxfromdk

    taxfromdk

    Joined:
    Oct 30, 2009
    Posts:
    95
    I think preprocessor should be able to do the trick. I just need to configure what scenes need to be built for that given platform.

    I aim to build the assetbundles after the build via my [PostProcessBuild] tagged function.

    My code use the ContinuationManager from here to be able to use the WWW class from editor script.

    My code is this:

    using UnityEngine;
    using UnityEditor;
    using UnityEditor.Callbacks;
    using System.Collections;

    public class MyBuildPostprocessor
    {
    static string url = "http://kanako.dk/test.html";

    [PostProcessBuild]
    public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
    Debug.Log( pathToBuiltProject );
    Debug.Log( target.ToString() );
    //CreateAssetBundles.BuildAllAssetBundles ();

    var www = new WWW(url);
    ContinuationManager.Add(() => www.isDone, () =>
    {
    if (!string.IsNullOrEmpty(www.error)) Debug.Log("WWW failed: " + www.error);
    Debug.Log("WWW result : " + www.text);
    });
    }

    [MenuItem ("Assets/Test")]
    public static void Test()
    {
    Debug.Log ("Test");
    var www = new WWW(url);
    ContinuationManager.Add(() => www.isDone, () =>
    {
    if (!string.IsNullOrEmpty(www.error)) Debug.Log("WWW failed: " + www.error);
    Debug.Log("WWW result : " + www.text);
    });
    }
    }
     
  7. taxfromdk

    taxfromdk

    Joined:
    Oct 30, 2009
    Posts:
    95
    My problem is basically that I need different scenes included in the build on different platforms. So:

    Web:
    MainScene in build
    Game1 in assetbundle
    Game2 in assetbundle

    IOS
    MainScene in build
    Game1 in build
    Game2 in build

    As I understand it I need to modify the scene list to make that happen, and Im unsure how to do that using preprocessor variables.

    Perhaps I can put an empty scene in the scene list build my entire game in the post
     
  8. David-Berger

    David-Berger

    Unity Technologies

    Joined:
    Jul 16, 2014
    Posts:
    740
    You can create custom scene lists in the studio tier, but it might be possible via scripts in lower tiers too.

    About the code, how do you upload those files? Does the server receive files? Have you already tried by uploading a simple text files or image before sending binary data? I would assume the ContinuationManager is comparable to this? Because if yielding is a problem it should also work with subroutines, I did not encounter problems with yielding there in editor scripts afaik.
     
  9. taxfromdk

    taxfromdk

    Joined:
    Oct 30, 2009
    Posts:
    95
    I tried using the WWW class alongside the ContinuationManager but I cant see it reach my webserver from the cloud.

    No files uploaded yet.

    Ill give the yield a go.

    Thanx for the input :)

    Jesper
     
  10. taxfromdk

    taxfromdk

    Joined:
    Oct 30, 2009
    Posts:
    95
    I can now upload files to our webserver using the WWW object with a WWWForm object. :)

    Will try to build assetbundles tomorrrow.
     
    David-Berger likes this.