Bundle To Copy regex not added

Hello,

I am trying the Bundle To Copy option in Unity Cloud Service web interface. But I cannot add a regex. Button do nothing.

I have created 3 Asset Bundles and want to only copy one to streaming assets folder.

Maybe using Pre-Export Method is a workarround? But seems to have Copy issue: Pre-export method to copy AssetBundles into StreamingAssets folder - Unity Services - Unity Discussions

I am very interested to know if someone managed to use Bundle To Copy option to only copy some assetBundles to streamingAssets folder?

I need it to only include starter assets, others are downloaded via other cloud server.

Then the Button add does not wrok like others for instance for Add Scripting Define Symbols.

Then I have create my own script to made AssetBundles before build with the pre-method export fields.

You have to create an AssetBundles folders at same level of Assets/ with subfolders for each plateform you support
ie: AssetBundles/WebGL

In git add a dummy.txt file for version control the folders.

Add an Assets/StreamingAssets folder with a dummy.txt file and version it to.

On unity Cloud Build Config go to Hide Advanced option of each build target and set Pre-Export method : PreExport.BuildAssetBundles

Then create build.

The code that you must add in Assets/Editor/PreExport.cs file
Just modify for your use (ie modifiy bundles to copy):

using UnityEditor;
using UnityEngine;

public class PreExport : Editor {
   
   
#if UNITY_STANDALONE_WIN
    /*[MenuItem("Resources/AssetsBundles/Build Asset Bundles/Windows 32")]
    static void BuildWindows()
    {
        Build(BuildTarget.StandaloneWindows, "Assets/StreamingAssets");
    }*/

    [MenuItem("Resources/AssetsBundles/Build Asset Bundles/Windows 64")]
    static void BuildAssetBundles()
    {
        Build(BuildTarget.StandaloneWindows64, "AssetBundles/Win64");
    }
#endif
       
#if UNITY_WSA

        [MenuItem("Resources/AssetsBundles/Build Asset Bundles/Windows Phone Store")]
        public static void BuildAssetBundles()
        {
            Build(BuildTarget.WSAPlayer, "AssetBundles/WSA");
        }
#endif

#if UNITY_ANDROID
        [MenuItem("Resources/AssetsBundles/Build Asset Bundles/Android")]
        public static void BuildAssetBundles()
        {
            Build(BuildTarget.Android, "AssetBundles/Android");
        }
#endif

#if UNITY_IOS
        [MenuItem("Resources/AssetsBundles/Build Asset Bundles/iOs")]
        public static void BuildAssetBundles ()
        {
            Build (BuildTarget.iOS, "AssetBundles/IOS");
        }
#endif

#if UNITY_WEBGL
        [MenuItem("Resources/AssetsBundles/Build Asset Bundles/Web GL")]
        public static void BuildAssetBundles ()
        {
            Build (BuildTarget.WebGL, "AssetBundles/WebGL");
        }
#endif

#if UNITY_WSA_10_0
        [MenuItem("Resources/AssetsBundles/Build Asset Bundles/Windows 10 Apps")]
        public static void BuildAssetBundles ()
        {
        Build (BuildTarget.WSAPlayer, "AssetBundles/WSA_10");
        }
#endif

#if UNITY_STANDALONE_OSX
        [MenuItem("Resources/AssetsBundles/Build Asset Bundles/MacOSX")]
        public static void BuildAssetBundles ()
        {
            Build (BuildTarget.StandaloneOSXUniversal, "AssetBundles/MacOSX");
        }
#endif

  

    // Build specific target
    static void Build(BuildTarget target, string path)
    {
        Debug.Log("Build Asset Bundles");
        BuildPipeline.BuildAssetBundles(path,
                                        BuildAssetBundleOptions.None,
                                        target);

        CopyAssetBundlesToStreamingAsset();
    }


    [MenuItem("Resources/AssetsBundles/Get AssetBundle names")]
    static void GetNames()
    {
        var names = AssetDatabase.GetAllAssetBundleNames();
        foreach (var name in names)
            Debug.Log("AssetBundle: " + name);
    }

    [MenuItem("Resources/AssetsBundles/Copy AssetBundles to StreamingAssets")]
    static void CopyAssetBundlesToStreamingAsset()
    {
        Debug.Log("Copy assetBundles");

#if UNITY_ANDROID
            FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/sprites_stream");
            FileUtil.CopyFileOrDirectory("AssetBundles/Android/sprites_stream", "Assets/StreamingAssets/sprites_stream");
           
#elif UNITY_IOS
            FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/sprites_stream");
            FileUtil.CopyFileOrDirectory("AssetBundles/IOS/sprites_stream", "Assets/StreamingAssets/sprites_stream");
#elif UNITY_WEBGL

            FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/sprites_stream");
            FileUtil.CopyFileOrDirectory("AssetBundles/WebGL/sprites_stream", "Assets/StreamingAssets/sprites_stream");
#elif UNITY_STANDALONE_WIN
        FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/sprites_stream");
        FileUtil.CopyFileOrDirectory("AssetBundles/Win64/sprites_stream", "Assets/StreamingAssets/sprites_stream");
#elif UNITY_WSA
        FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/sprites_stream");
            FileUtil.CopyFileOrDirectory("AssetBundles/WSA/sprites_stream", "Assets/StreamingAssets/sprites_stream");
#elif UNITY_WSA_10_0
        FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/sprites_stream");
            FileUtil.CopyFileOrDirectory("AssetBundles/WSA_10/sprites_stream", "Assets/StreamingAssets/sprites_stream");
#elif UNITY_STANDALONE_OSX
        FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/sprites_stream");
            FileUtil.CopyFileOrDirectory("AssetBundles/MacOSX/sprites_stream", "Assets/StreamingAssets/sprites_stream");
#endif
    }

    [MenuItem("Resources/AssetsBundles/Delete Asset Bundles Cache")]
    static void CleanCache()
    {
        if (Caching.CleanCache())
        {
            Debug.LogWarning("Successfully cleaned all caches.");
        }
        else
        {
            Debug.LogWarning("Cache was in use.");
        }

    }
}

Hope Unity will fix the Bundle To Copy button Add, because does not work at all.

We looked into it and found a bug in the website interface for adding file copy patterns. We’ll get it fixed soon.

-Stephen

1 Like

Great I have see today that you fixed the issue. Add button works now.

But: When you set build asset bundles and copy them to streamingassets folder then PreExport Method is clear.

Why? We cannot have PreExport method and build assetbundles togother? And the reverse is also available. If you setup BuildAsset bundles options and add a preexport method, then AssetBundles options are cleared.

Edit: now we cannot copy file in PreExport method (always failed compil now). Then we are mandatory to use AssetBundles options to copy to StreamingAssets folder. Then PreExport and PostExport method must be accessible to for instance increase build number …

I juste test on another project and Pre Export method can copy Asset Bundles build from my script to StreamingAssets as before.

Then I think it is my test project that is broken in UCB. Cannot copy, before this works well, and new Asset Bundles Options to cbuild and copy does not works weel. See logs:

something happens at the moment where Unity will create the UCB manifest file

My project is:
TestCloudBuild