- Home /
How do folks organize and download AssetBundles for different platforms?
Hi,
I have a multiplatform application, so I need to build the AssetBundles for each platform, and then I store them on my website, in a platform-specific directory, based on the buildTarget. So, the iOS AssetBundle goes into ./iOS, and StandaloneWindows into ./StandaloneWindows and so on.
So, when the Player needs to download the AssetBundle, it needs to construct the URL at runtime. But, the buildTarget is not available at runtime.
How do people deal with this sort of thing? It seems like such a basic problem, but I don't see a whole lot of people talking about it, so I must be missing something.
Answer by Bonfire-Boy · Sep 07, 2021 at 11:32 AM
Why do you need it to be available at runtime? A specific build of the player only works on one platform anyway, and it's available when building...
#if UNITY_IOS
const string folder="iOS";
#elif UNITY_STANDALONE_WIN
const string folder = "StandaloneWindows";
#endif
// and so on
because we download them and I need to know which file to download
Same principle applies, whether you're keeping the platform-specific files in different folders on the server, and/or giving them different filenames (which is very much recommended - giving the same filename to ABs for different platforms would be madness IMO). You've got all the info you need when you build the app, you don't need to work it out at runtime.
But obviously, if you did need the info at runtime for some other reason, you could make it available in exactly the same way. The folder string shown for example, is in fact something that's available at runtime. that tells you what platform the app was built for.
If this doesn't work for you then please give more details of what you're trying to do. I've made a fair few apps which use platform-specific and versioned downloadable asset bundles and have to say this side of things has always been pretty straightforward. Its the versioning and dependencies side of things that can get complicated, rather than the platform-specific stuff.
Duh. That's a good point, @Bonfire-Boy . @DaveBurlingame - Bonfire is right. Set the string "folder" at compile time, and then use that value at runtime.
Answer by DaveBurlingame · May 13, 2021 at 08:53 PM
I have the same question and could not find an answer. There is EditorUserBuildSettings.activeBuildTarget and Application.RuntimePlatform. They don't match up. And there is a very simple matrix at https://docs.unity3d.com/550/Documentation/Manual/AssetBundleFAQ.html but it's a guideline. So I am not sure how to do it other than to hard code it somewhere with a bunch of conditions
For better or worse, I decided to use 3 letter file extensions for the different platforms