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 /
  • Help Room /
This question was closed Apr 20, 2016 at 06:22 PM by Milfeulle9 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Milfeulle9 · Feb 19, 2016 at 09:36 AM · androidsplitdownloadingobb

Trouble downloading OBB files with Android split binary application deployment

Hi.

First of all, I'd like to clear up that the split binary is not intended to be uploaded to Google Play, but to another distribution service that's similar to it.

Here's the problem: I can already download and move the file to the Android/obb/com.companyname.productname path, but when going I try to go to the next scene it just stays in the initial scene. Upon restarting the app it just stays frozen on the Unity splash screen and doesn't do anything. I've already checked multiple times and the OBB file is indeed correctly downloaded in the internal storage.

I have tried downloading the file to external storage as well, but to no avail, so I have no idea if that's even the problem.

However, moving the file manually to the obb folder before starting the game seems to make it work.

Here's my code:

 void Start ()
     {
         if (currentVersion != "13")        
             notCurrent = true;        
         else
             notCurrent = false;
 
 #if UNITY_ANDROID
         if (!needsOBB)
         {
             SceneManager.LoadScene("Splash");
         }
 #else
         SceneManager.LoadScene("Splash"); 
 #endif
 
         if (needsOBB)
         {
             bundleIdentifier = Application.bundleIdentifier + "/";
             fileName = string.Format("main.{0}.{1}.obb", 13, Application.bundleIdentifier);
 
             fullTargetUrl = targetUrlPath + fileName;
             obbFullPath = obbPath + bundleIdentifier + fileName;
 
             if (File.Exists(obbFullPath))
             {
                 SceneManager.LoadScene("Splash");
             }
 
             directories.text = string.Format("File Path = {0} \n", obbFullPath);
             directories.text += string.Format("Target download URL = {0}", fullTargetUrl);
 
             if (!testDownload)
                 StartCoroutine(DownloadAndroid());
             else if (testDownload)
                 StartCoroutine(DownloadPC());
         }
 
     }
 
     private IEnumerator DownloadAndroid()
     {
         //if (File.Exists(obbFullPath) && notCurrent)
         //{
         //    File.Delete(obbFullPath);
         //    yield return null;
         //}
 
         WWW www = new WWW(fullTargetUrl);
 
         string obbPathPlusIdentifier = obbPath + bundleIdentifier;
 
         Directory.CreateDirectory(obbPathPlusIdentifier);
 
         while (!www.isDone)
         {                        
             if (!File.Exists(obbFullPath))
             {
                 progress = ((int)(www.progress * 100)).ToString() + "%";
                 progressBar.GetComponent<Image>().fillAmount = www.progress;
                 progressText.GetComponent<Text>().text = progress;
                 yield return null;
             }
         }
 
             if (!File.Exists(obbFullPath))
             {
                 progressBar.GetComponent<Image>().fillAmount = 1;
                 File.WriteAllBytes(obbFullPath, www.bytes);
                 progress = "Done";
                 progressText.GetComponent<Text>().text = progress;
                 SceneManager.LoadScene("Splash");
             }
         
 
     }
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

  • Sort: 
avatar image
0
Best Answer

Answer by Milfeulle9 · Apr 20, 2016 at 02:57 PM

Yes, I have, actually.

The problem was that I was trying to copy the file asynchronously while also loading the next scene. This would cause the .obb file to be copied over, but be corrupted.

To solve this, just make sure you do the file copying in Update, so the sequence of events isn't asynchronous and it goes step by step, like this:

    void Update()
     {
         if (needsOBB)
         {
             if (activated)
             {
                 if (File.Exists(obbFullPath))
                 {
                     SceneManager.LoadScene(1);
                 }
                 else
                 {
                     if (!testDownload)
                         StartCoroutine(DownloadAndroid());
                     else if (testDownload)
                         StartCoroutine(DownloadPC());
 
                     activated = false;
                 }
             }
 
         }
 
         if (FileIsSaved)
         {
             StopCoroutine("DownloadAndroid");
             SceneManager.LoadScene(1);
         }
 }

private IEnumerator DownloadAndroid() {

     while (!www.isDone)
     {                        
         if (!File.Exists(obbFullPath))
         {
             if (!string.IsNullOrEmpty(www.error))
             {
                 downloadFailedDialog.SetActive(true);
                 progressText.GetComponent<Text>().text = "Download Fail";
                 progressBar.GetComponent<Image>().fillAmount = 1;
                 www.Dispose();
                 StopCoroutine("DownloadAndroid");
             }

             elapsedTime = 0.0f;
             isDownloading = true;

             progress = ((int)(www.progress * 100)).ToString() + "%";
             progressBar.GetComponent<Image>().fillAmount = www.progress;
             progressText.GetComponent<Text>().text = progress;
             yield return null;
         }
     }

     if (www.isDone)
     {
         if (!File.Exists(obbFullPath))
         {
             File.WriteAllBytes(obbFullPath, www.bytes);
             progressBar.GetComponent<Image>().fillAmount = 1;

            ...

             yield return new WaitForSeconds(timeToRestart);

             FileIsSaved = true;

         }
     }        

 }


You can see that instead of switching scenes in the coroutine I've made it so it's done in Update instead.

Hope this helps anyone else with this problem.

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 dNSavar · Apr 20, 2016 at 03:17 PM 0
Share

Thanks a lot!

avatar image
0

Answer by dNSavar · Apr 20, 2016 at 06:16 AM

I have the same problem, do you have found a solution?

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Android Project Split Build Troubles 0 Answers

Issue with the OBB Downloader plugin 0 Answers

Path to streamingassets obb video 0 Answers

Unity 5.4 Android OBB - Blank scene being loaded with Camera over-draw 1 Answer

Unity and Vuforia on Android: Could Not Load Video from OBB 1 Answer


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