Downloading Prefab and getting a error

Hello,

I have a prefab working on my project.
I uploaded it to a server (mime-type: application/binary) and downloaded it again, it still works on importing to the project, you can check it for yourselfs:

http://35.194.86.108:2444/fda/Arquivos/Fotos/5/AR/1064.prefab

Now I´m importing it via this script:

StartCoroutine(DownloadPrefab(“http://35.194.86.108:2444/fda/Arquivos/Fotos/5/AR/1064.prefab”));

IEnumerator DownloadPrefab(string URL)
{
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(URL);
yield return www.SendWebRequest();

if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);:wink:
}
else
{
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
Debug.Log(bundle.GetAllAssetNames());//ERROR
//while downloading Asset Bundle: Failed to decompress data for the AssetBundle
}
}

Whats going on?

thanks

So is it an assetbundle you’ve hosted with a .prefab extension, or is it the actual prefab as it lives in your assets folder?

1 Like

It´s the actual prefab as it lives in my assets folder…

Oh god… how does it change my code? Thinking about it right now…

Your runtime code is probably right (or close to it), but you need to google AssetBundles and how to create them.

1 Like

So… there was an misunderstanding from my part, prefab x assetbundle, alright, I get it. But…

The prefab was 431kb. The assetbundle, more than 6Mb.

And, looking at this code taken from Unity itself:
(Unity - Manual: AssetBundle workflow)

public class CreateAssetBundles
{
[MenuItem(“Assets/Build AssetBundles”)]
static void BuildAllAssetBundles()
{
string assetBundleDirectory = “Assets/AssetBundles”;
if(!Directory.Exists(assetBundleDirectory))
{
Directory.CreateDirectory(assetBundleDirectory);
}
BuildPipeline.BuildAssetBundles(assetBundleDirectory,
BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows);//HERE
}
}

Do I need to make a assetbundle for each platform? One Windows to tests, one Android, one iOS…? And a URL different for each one? It will be a pain…

I revert the question:

And if I didnt want a assetbundle, if I want really download just a 431kb prefab for both Android and iOS and Windows?

Is it possible?

Thank you for your patience, @nilsdr @StarManta

No, it’s not possible to get a prefab without using an AssetBundle. However, it’s certain that either A) the AssetBundle is much larger than it needs to be, or B) the prefab is much smaller than it needs to be. The .prefab file doesn’t include any assets (textures, animations, etc), but those are absolutely needed to function and they will almost always be much larger than the prefab. When it makes the AssetBundle, it includes those dependencies.

2 Likes

Well, this question is turning much different from what I was thinking… (which is good, somehow…)

I understood yours A x B itens, good.

Lets say I didnt want a prefab. I just want a .fbx model to be loaded that way, via download.

Will that work?

(I know, there´s a lot of “google” in here, but… thats a good talk anyway)

You’d have to handle importing the FBX file yourself. Which is possible, and I think I’ve seen a plugin before that can do that. I found this one with a quick search that may work.

1 Like

Thank you.

I will follow from here (with new understandings…)