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. Dismiss Notice

Obb Expansion was Downloaded Automatically

Discussion in 'Android' started by rakifsul, Dec 18, 2014.

  1. rakifsul

    rakifsul

    Joined:
    Mar 30, 2014
    Posts:
    47
    Hi guys,

    Yesterday, i was trying to test a game with split binary enabled. I attached an Obb downloader script from (https://www.assetstore.unity3d.com/en/#!/content/3189) with some modifications from (http://www.exoa.fr/tutorial-unity-4-apk-splitting-google-play-obb/)

    But something weird happened. When i downloaded my game (alpha version) from google play, google play downloaded the obb file before i run the game (the obb downloader script was not working but google play downloaded the obb before the game installation begin).

    Is this normal (or a new feature from google play) ? Do we still need an obb downloader script attached to our scene loader?
     
  2. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    I think that that's how it's supposed to work. As far as I understand, obb downloader is required in cases where the obb file didn't download automatically due to connection problems or insufficient free space, etc.

    P.S. I don't really understand what's the point of this binary splitting altogether to be honest. I don't understand why Google Play can't force-download the obb files before the game can be launched, so you don't have to deal with it yourself.
     
  3. rakifsul

    rakifsul

    Joined:
    Mar 30, 2014
    Posts:
    47
    I think you're right. I tried to delete the obb folder and file and the dowloader script is working. However it doesn't load the next scene after obb download finished. What is wrong with my code? This is the downloader script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DownloadObbExample : MonoBehaviour
    5. {
    6.     private string expPath;
    7.     private string logtxt;
    8.     private bool alreadyLogged = false;
    9.     private string nextScene = "SceneMenu";
    10.     private bool downloadStarted;
    11.  
    12.     public Texture2D background;
    13.     public GUISkin mySkin;
    14.  
    15.     void log( string t )
    16.     {
    17.         logtxt += t + "\n";
    18.         print("MYLOG " + t);
    19.     }
    20.     void OnGUI()
    21.     {
    22.         //GUI.skin = mySkin;
    23.         GUI.DrawTexture(new Rect(0,0,background.width,background.height),background);
    24.      
    25.         if (!GooglePlayDownloader.RunningOnAndroid())
    26.         {
    27.             GUI.Label(new Rect(10, 10, Screen.width-10, 20), "Use GooglePlayDownloader only on Android device!");
    28.             return;
    29.         }
    30.      
    31.         expPath = GooglePlayDownloader.GetExpansionFilePath();
    32.         if (expPath == null)
    33.         {
    34.             GUI.Label(new Rect(10, 10, Screen.width-10, 20), "External storage is not available!");
    35.         }
    36.         else
    37.         {
    38.             string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
    39.             string patchPath = GooglePlayDownloader.GetPatchOBBPath(expPath);
    40.             if( alreadyLogged == false )
    41.             {
    42.                 alreadyLogged = true;
    43.                 log( "expPath = "  + expPath );
    44.                 log( "Main = "  + mainPath );
    45.                 log( "Main = " + mainPath.Substring(expPath.Length));
    46.              
    47.                 if (mainPath != null)
    48.                     StartCoroutine(loadLevel());
    49.              
    50.             }
    51.             //GUI.Label(new Rect(10, 10, Screen.width-10, Screen.height-10), logtxt );
    52.          
    53.             if (mainPath == null)
    54.             {
    55.                 GUI.Label(new Rect(Screen.width-600, Screen.height-230, 430, 60), "The game needs to download 200MB of game content. It's recommanded to use WIFI connexion.");
    56.                 if (GUI.Button(new Rect(Screen.width-500, Screen.height-170, 250, 60), "Start Download !"))
    57.                 {
    58.                     GooglePlayDownloader.FetchOBB();
    59.                     StartCoroutine(loadLevel());
    60.                 }
    61.             }
    62.          
    63.         }
    64.      
    65.     }
    66.     protected IEnumerator loadLevel()
    67.     {
    68.         string mainPath;
    69.         do
    70.         {
    71.             yield return new WaitForSeconds(0.5f);
    72.             mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);  
    73.             log("waiting mainPath "+mainPath);
    74.         }
    75.         while( mainPath == null);
    76.      
    77.         if( downloadStarted == false )
    78.         {
    79.             downloadStarted = true;
    80.          
    81.             string uri = "file://" + mainPath;
    82.             log("downloading " + uri);
    83.             WWW www = WWW.LoadFromCacheOrDownload(uri , 0);      
    84.          
    85.             // Wait for download to complete
    86.             yield return www;
    87.          
    88.             if (www.error != null)
    89.             {
    90.                 log ("wwww error " + www.error);
    91.             }
    92.             else
    93.             {
    94.                 Application.LoadLevel(nextScene);
    95.             }
    96.         }
    97.     }
    98. }
     
  4. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    You should ask a mod to move this in the Android section and not ask these in general discussion.
     
  5. rakifsul

    rakifsul

    Joined:
    Mar 30, 2014
    Posts:
    47
    I'm sorry. but how to contact the mod? Also, i cannot find Android section in this forum.
     
  6. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    Its under platforms section. You can click the report button in your 1st post and write move req.
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    The easiest way is to hit the "Report" button under the post.
    It can let you download only the content packages relevant to a particular device, right? Eg: you have low and high DPI art for use on different devices, you can get it to grab only the relevant one?
     
  8. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    Is that actually true?
    I don't know how splitting the binary works, but I don't think you can choose what gets into each of the two obb files.
     
  9. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    I don't know. That's why it was a question. ;)
     
  10. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You can create multiple APKs for different device types (and those APKs can have their own OBB files), but I don't know of any way to sort out the OBB files for specific art assets.
     
  11. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    I had it understood that the obb files were supposed to be like one is simply additional data, and the other was a kind of "patch" to that first data. I don't know for sure as I've never made one that needed more than the first one.

    I also had it understood that Google Play itself handled the download of the obb. I didn't even know about you having to make it do so in the game itself, so that is new to me too. That simply sucks though in any case. I'm not understanding(never have) why Google wants to put the 50MB limit. Other markets don't have the issue, so it isn't like it is a defect of APK files or Android. Also, there is enough warnings etc... about only downloading big files over WIFI, etc... that you would think we know what we are doing if we are the consumer anymore. I know some people know more than others, but generally the carrier warns people, or limits the bandwidth when they have too much downloaded, or simply stops the data. So like I say, I've never understood why Google forces the 50MB limit.