1

I would like to ask if anyone create Assetbundle in Unity on cloud? I would like to generate the AssetBundle dynamically on cloud and the client app will download it accordingly.

Could you let me know your idea? Is there any cloud service for hosting Unity ?

Steven
  • 166,672
  • 24
  • 332
  • 435
Souris
  • 326
  • 1
  • 5
  • 13

2 Answers2

3

The accepted answer is spot on but there are slight changes as Unity5.6 now supports every other feature in the free version too. I've been working on a similar project that required building asset bundles dynamically. I'll post my code snippet for the same so that the process of identifying this gets simpler for everyone else in future.

But before that, there are some limitations for this process that you may need to consider. Building asset bundles dynamically on cloud requires (Command line) batchmode which runs Unity on commandline (Unity should be installed to build bundles). This asset building process works only on Windows and OSX (No Linux). The command to invoke Unity in batch mode is given below and has to be executed from Unity executable's location,

this command creates an empty project,

Unity -batchmode -quit -createProject <path/to/create a project>

After creating a project, you can save a script to build assets in the Assets/Editor folder, I have a written a script to automate the process of building assetbundle for all assets in the Assets/Models folder.

//BuildAssets.cs
using System.Collections;
using System.Collections.Generic;

public class BuildAssets : UnityEngine.MonoBehaviour
{
static void BuildAssetBundle()
{
    int i = 0;
    string log = "log.txt";
    string[] assetN;
    int N_Files;
    UnityEditor.AssetBundleBuild[] AssetMap = new UnityEditor.AssetBundleBuild[2];
    AssetMap[0].assetBundleName = "res";

    // Adding to path /Models
    string path = UnityEngine.Application.dataPath + "/Models";

    //log
    System.IO.File.AppendAllText(log, System.DateTime.Now.ToString() + "\n\n");
    System.IO.File.AppendAllText(log, path + "\n");


    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
    System.IO.FileInfo[] files = dir.GetFiles();

    // Number of files in "/Models" folder
    N_Files = files.Length;

    //log
    System.IO.File.AppendAllText(log, "Num assets: "+N_Files + " \n");


    assetN = new string[N_Files];
    foreach (System.IO.FileInfo file in files)
    {
        if (file.Exists)
        {
            if (!file.Extension.Equals(".meta"))
            {
                assetN[i] = "Assets/Resources/" + file.Name;
                System.IO.File.AppendAllText(log, assetN[i] + " \n");
                i += 1;
            }
        }
    }
    AssetMap[0].assetNames = assetN;

    UnityEditor.BuildPipeline.BuildAssetBundles("Assets/AssetBundles", AssetMap, UnityEditor.BuildAssetBundleOptions.None, UnityEditor.BuildTarget.Android);
    System.IO.File.AppendAllText(log, "\t----X----\n"); //log
   }
}

This is the command for building the asset bundle through command line.

Unity -batchmode -quit -projectPath path/to/UnityProjects/Projectname -executeMethod BuildAssets.BuildAssetBundle -logFile <Log file location>

I've tested this and it works for our project.

Arvind
  • 730
  • 10
  • 20
0

AssetBundles require unity pro to build. There is a command line batch mode that you can use to build your asset bundles automaticly and host it on virtualy any host (a simple HTTP get).

Remember that you might not need asset bundles (or unity pro) - you can easily download textures and audio from the web using the WWW class. For textures you can use png, jpeg and tiff, for audio wav, ogg (only desktop and webplayer), mp3 (only mobile). Mesh loading should be also possible but that will require additional tools.

Krzysztof Bociurko
  • 4,575
  • 2
  • 26
  • 44
  • Thanks. But in fact, my question is how to generate the bundle on cloud. I know that it is possible to host the bundleasset on cloud. But is there anyway to generate the bundle on cloud also? – Souris Jul 10 '14 at 11:03
  • As i said, you have to have a working unity pro to generate the bundle. You can do this on a dedicated osx or windows server - this server can be in a cloud. Note that unity might require a separate license for this. – Krzysztof Bociurko Jul 10 '14 at 11:21
  • Thanks. Amazon now supports Windows Server. But I do not know if it is possible to run Unity Pro on that? And also, is it possible to call Unity Pro from a remote client? (e.g: a client site) – Souris Jul 10 '14 at 12:25
  • There is no built in functionality for running unity on a remote client, but all you sould have to do is do a web app/rpc that calls unity in batch mode. You will have to check with amazon if they will support Unity on their servers. – Krzysztof Bociurko Jul 10 '14 at 13:11