Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Downloading Prefab and getting a error

Discussion in 'Scripting' started by clebertavares, Oct 28, 2019.

  1. clebertavares

    clebertavares

    Joined:
    Jan 2, 2012
    Posts:
    55
    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);
    }
    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
     
  2. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    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?
     
    clebertavares likes this.
  3. clebertavares

    clebertavares

    Joined:
    Jan 2, 2012
    Posts:
    55
    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...
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,745
    Your runtime code is probably right (or close to it), but you need to google AssetBundles and how to create them.
     
    clebertavares likes this.
  5. clebertavares

    clebertavares

    Joined:
    Jan 2, 2012
    Posts:
    55
    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:
    (https://docs.unity3d.com/Manual/AssetBundles-Workflow.html)

    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
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,745
    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.
     
    clebertavares and Joe-Censored like this.
  7. clebertavares

    clebertavares

    Joined:
    Jan 2, 2012
    Posts:
    55
    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)
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,745
    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.
     
    clebertavares likes this.
  9. clebertavares

    clebertavares

    Joined:
    Jan 2, 2012
    Posts:
    55
    Thank you.

    I will follow from here (with new understandings...)