Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Asset Bundles not supported?

Discussion in 'PSM' started by Jonny-Roy, Jul 11, 2014.

  1. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Hi,

    I'm getting:

    The unity3d file is not a valid asset bundle.

    When loading a bundle built with:

    BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { scenePath }, path, BuildTarget.PSM, out crc);

    Are Scene asset bundles not supported or is there something I'm missing, it's the same code as on all other platforms.

    Thanks,

    Jon
     
  2. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    Actually it's something that PSM is missing not you :confused:
     
  3. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    As PeteD suggests - it might very well be connected with the fact that the Caching API is currently disabled for PSM.
    We are working on an update for PSM to solve this and a couple of other crucial problems found (most of them also discussed here on the forums).
     
  4. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Thanks guys!
     
  5. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    I think you're creating or loading the asset bundle incorrectly.

    Here is an example with both asset AssetBundles and scene AssetBundles.
    1. Import the package
    2. Create the asset bundles by right-clicking the StreamingAssets folder.
    3. Select the TestScene
    4. Then build&run as usual (you can also test it in the editor).
    Hope that helps.
     

    Attached Files:

  6. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Hi Erique,

    Unfortunatly the attached only works in the editor, when I deploy to a device it comes up with the error:

    [189.037467] HTTP status Code is 200
    [189.037989] HTTP start transfer of 9592 bytes
    [189.077889] HTTP end transfer
    [189.131682] The unity3d file is not a valid asset bundle.
    [189.132204] Bundle is null...
    [189.212019] HTTP release context

    All I changed was to upload the bundle to an online server and update the url as follows:

    private string CreateURL(string name)
    {
    return "http://www.xxxxxxxx.com/"+name;//"file://" + Application.streamingAssetsPath + "/" + name;
    }

    it still works fine in the editor but on the device it fails.

    Any thoughts?

    Thanks,

    Jon
     
  7. PeterD

    PeterD

    Joined:
    Feb 6, 2013
    Posts:
    120
    If name has spaces in it then that will not work over a www connection without being encoded. Reason being that many servers will replace spaces with a + symbol instead as a space in a url breaks the url. if I were looking for a file called "max is great" and simply typed it into a browser, well let me type it here and you can see that the url is only valid up until the first space in the filename without using encoding i.e. www.fred.com/max is great
     
  8. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Sorry Peter, if you look at the error you'll see the file is downloading fine, it's an issue with the asset bundles compilation or runtime use not the WWW class or the request...that's clear from the error log.
     
  9. PeterD

    PeterD

    Joined:
    Feb 6, 2013
    Posts:
    120
    Have you tried plugging your URL into a browser to see what is actually being returned?
     
  10. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Read the error, it's a 200 response confirming it's not the web request, and if you read the message you'll see it works in the editor, so I'm not sure what testing in a browser would achieve beside confirming exactly what the log already does. I've already properly debugged it, it is an issue with asset bundles on psm.
     
  11. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    That doesn't answer the question. Have you tried your link in a browser?
    A server returns a message based on how it's configured remotely. Just because your server is returning a 200 does not mean that it's returning a valid file. Simply plugging the url into a browser and checking if unity is able to read the returned file will tell you 100% if this is an issue with UnityPSM or your code. The error messages you've shown are just debug. For instance if you were to send a registration message to a push service like Pushwoosh it would return a 1000 code (registration succesful) even if there is an error as the error information is contained in a separate custom field. That's just the way that particular server works.
    So while you seem to think I'm ignoring your debug I am simply asking you if you've ACTUALLY checked what is happening when you send YOUR request to the server and a browser, which is independent of unity or your code, will verify exactly what is happening. Until then you haven't actually tested your file downloads properly at all.
     
    Last edited: Aug 12, 2014
  12. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    Bundle made in an up to date / same version Unity?
     
  13. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    I said you didn't read my message properly:

    "the attached only works in the editor"

    The url and downloaded to the editor works fine, what would downloading it separately and then putting into the editor test that running the code in the editor does not? The issue is asset bundles, as stated at the top of the thread the same code that works on all other platforms is used, it's tested properly you've just not read the thread properly. Don't get me wrong I appreciate your responses and that you have taken the time to make a suggestion, but it is not the download link, it's the asset bundle.

    Having tested further, it looks like unity is ignoring the compile to PSM and is compiling it to Stand Alone instead, which would follow as the bundle works in the Editor, yet no other platforms (iOS, BlackBerry and Android, etc) bundles work in the editor.
     
  14. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Yes, it works fine in the editor and every other platform, the same compiled bundle works in the Editor, Web Player and Stand Alone.
     
  15. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    On further investigation it's the WWW class that's the issue. Not sure what it's doing, but if you load the bundles from StreamingAssets it's fine, but downloading with WWW on PSM fails from a Url, the Editor works fine. I'll submit a bug report.
     
  16. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    For anyone wanting to do this:

    private string CreateURL(string name)
    {
    return "http://www.yoururl.com/"+name;
    }
    private string CreatePath(string name)
    {
    return "file://" + Application.persistentDataPath + "/" + name;
    }
    private string IOPath(string name)
    {
    return "file://" + Application.persistentDataPath + "/" + name;
    }
    private IEnumerator DownloadAssetBundle(string name)
    {
    var path=CreatePath(name);
    if (!System.IO.File.Exists(path))
    {
    WWW dl = new WWW(CreateURL(name));
    Debug.Log(CreateURL(name));
    yield return dl;
    if (dl.error != null)
    {
    Debug.Log("ERROR: " + dl.error);
    yield return 0;
    }
    System.IO.File.WriteAllBytes(IOPath(name), dl.bytes);
    }
    WWW www = new WWW(path);
    yield return www;
    if (www.error != null)
    {
    Debug.Log("ERROR: " + www.error);
    yield return 0;
    }
    AssetBundle ab = www.assetBundle;
    if(ab!=null)
    {
    Object obj = (Object) ab.mainAsset;
    GameObject pGO = (GameObject) obj;
    if (pGO == null)
    Application.LoadLevelAdditive(System.IO.Path.GetFileNameWithoutExtension(name));
    else
    Instantiate(pGO,new Vector3(.0f,.0f,.0f),pGO.transform.rotation);
    }
    else
    {
    Debug.Log ("Bundle is null...");
    }
    }

    Is the workaround I'm using that works, it seems to still be an issue with the .LoadFromCacheOrDownload command.
     
  17. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    Building streamed scenes works fine for me did you actually set the scenes up to be loaded via WWW? as in

    BuildOptions.BuildAdditionalStreamedScenes
     
  18. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    No, because it only needs the single scene in the bundle, plus this would not return the error above.
     
  19. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    I'm not sure I understand your logic. The build option above is needed if you are creating an asset bundle of a scene, be that a single scene or multiple scenes. Are you saying you omited the build options because you were only building a single scene into the asset bundle and the options name is plural BuildAdditionalStreamedScenes

    Edit: Hopefully EriQue can explain asset bundle creation to you better.
     
  20. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    I don't need an explanation, firstly, aside from the first post where it was code I had written for a game for Audi, currently out on iOS, Android, BB10 and Windows Phone which uses the same code yet works perfectly doesn't work on PSM. All the posts following are using EriQue sample code, which incidentally is the same as mine.

    You should generally not use the method you are suggesting as it is not the recommended way to build a streamed scene, from the documents: "The best way to build a streamed scene asset bundle is to use BuildPipeline.BuildStreamedSceneAssetBundle" which is the technique both me and EriQue used.
     
  21. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Indeed - it seems there is a problem when the WWW (using http://) feeds the AssetBundle loader directly.
    Sorry about that - we'll try to have it fixed as soon as possible.
     
  22. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Thanks eriQue, no need to apologise.