Using a custom build script to make assetbundles for web

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

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 :sunglasses:

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

I found an article explaining how I can use yield against a www request.

It works when building locally, but the build bot does not seem to hit my webserver. Is it sandboxed?

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?

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);:wink:
Debug.Log("WWW result : " + www.text);:wink:
});
}

[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);:wink:
Debug.Log("WWW result : " + www.text);:wink:
});
}
}

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

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.

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 :slight_smile:

Jesper

I can now upload files to our webserver using the WWW object with a WWWForm object. :slight_smile:

Will try to build assetbundles tomorrrow.

1 Like