Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by naviln · Dec 23, 2017 at 04:51 AM · androidandroid buildassetbundleassetbundlesassetbundle.loadasync

AssetBundleManager.LoadAssetAsync() doesn't work on some android devices (or is very slow)

Hi guys,


I'm having a strange problem with the AssetBundleManager.LoadAssetAsync() method on some android devices.


All desktop and iOS platforms work fine, with art loading close to instantly.


A samsung galaxy s5 is able to load the card art, with a very slight delay (microseconds).


But a samsung galaxy s7 and a galaxy tablet is unable to load the cardart sprites (some users report it will randomly appear, after a veeerry long wait).


I was using unity 2017.2, but went back to 5.6.2 hoping the issue would resolve. No luck.


One difference I could see between the devices is that the galaxy s5 has a microsd card, and some of the gamedata appears to be stored on there. Not sure if this is relevant, but just thought I'd mention (in case there is some performance benefit with having streamingassets on a sd card)


Here is the code of what I am trying to do: (which is a copy of the sample from here: https://docs.unity3d.com/Manual/AssetBundles-Manager.html)


 AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync("cardart", card["Art"], typeof(Sprite));
 
 //if no cardart to load, try again next update
 if (request == null)
 {
     yield break;
 }
 else
 {
     //run the method to get the card art
     yield return StartCoroutine(request);
 
     Sprite newimage = request.GetAsset<Sprite>();
     if (newimage != null)
     {
         cardart.sprite = newimage;
         yield break;
     }    
 }




Has anyone else seen this problem? What am i doing wrong? Is there an alternative to LoadAssetAsync() I can try? I'm happy to post more code (The full AssetBundleManager class that I am using) if that helps with analysis?


Could someone please assist as I am going nuts trying to resolve this, and it's holding up the android release of the game!!


Any response is much appreciated
Cheers
Navil

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by naviln · Dec 27, 2017 at 05:56 AM

After many painful hours spent debugging on android, I found myself an answer.


In the hope that it helps someone, I am posting it here.

The culprit appeared to be the override call to Update() in the AssetBundleLoadOperation.cs class. This is the original code that I had:


 // Returns true if more Update calls are required.
         public override bool Update ()
         {
             if (m_Request != null)
                 return false;
 
             LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle (m_AssetBundleName, out m_DownloadingError);
             if (bundle != null)
             {
                 ///@TODO: When asset bundle download fails this throws an exception...
                 m_Request = bundle.m_AssetBundle.LoadAssetAsync (m_AssetName, m_Type);
                 return false;
             }
             else
             {
                 return true;
             }
         }


Subsequent calls to Update() for an asset would immediately return false, indicating that it is ready for cleanup, when in reality the asset could still be loading. I updated the method to below, which waited for the asset to appear before allowing it to return false.


         //Returns true if more Update calls are required.
         public override bool Update()
         {
             if (m_Request != null)
             {
                 //check if its done properly!
                 var completedCheck = m_Request.isDone;
 
                 if (completedCheck)
                 {
                     //this means its finished! but still not working. let's check if the asset is there yet
                     var assetLoaded = m_Request.asset;
 
                     //sprite there?
                     if (assetLoaded != null)
                     {
                         //change its priority
                         m_Request.priority = 1;
                         //and return false. (allow it to complete now)
                         return !completedCheck;
                     }
                     else if (!completedCheck)
                     {
                         //if the asset it STILL not there, that means there is some more to go. keep returning true.
                         return true;
                     }
                 }
                 else
                 {
                     //keep returning true, we haven't finished yet
                     return true;
                 }
             }
 
             LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);
             if (bundle != null)
             {
                 //@TODO:When asset bundle download fails this throws an exception...
                 m_Request = bundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type);
 
                 //make it a higher priority.
                 m_Request.priority = 2000;
 
                 //don't return false here? we haven't quite finished the request yet? return true.
                 return true;
             }
             else
             {
                 return true;
             }
         }    
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by carlosfarinhas · Jun 01, 2018 at 05:05 PM

Hi, it didn't work for me! Android still slow downloading assetbundles.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image naviln · Jan 29, 2019 at 12:21 AM 0
Share

You will probably have to debug your application on the android to work out what is going wrong.

Try this link for setting up debugging on Android: https://docs.unity3d.com/2017.4/Documentation/$$anonymous$$anual/Attaching$$anonymous$$onoDevelopDebuggerToAnAndroidDevice.html

And I posted an answer here that might help: https://answers.unity.com/questions/1145960/attach-to-process-never-shows-my-device.html

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AssetBundles don't load to scene on Android device. 3 Answers

How can i connect the smartphone's photogallery with app just build? 0 Answers

Can a windows and an android app use the same assetbundle specified with no target?,Can Windows and Android apps run assetsbundles with notarget? 0 Answers

More than one file was found with OS independent path 'kotlin/reflect/reflect.kotlin_builtins' 1 Answer

Too slow switching for android in Unity3D 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges