Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Force Android Unity to recognize a newly downloaded OBB without having to restart the app?

Discussion in 'Android' started by ChricKCK, Jan 24, 2020.

  1. ChricKCK

    ChricKCK

    Joined:
    May 9, 2014
    Posts:
    8
    Hi.

    We're forced to rely on the OBB approach over the asset bundle approach due to game-to-market time constraints. As part of the OBB implementation, we've implemented a custom OBB downloader activity to download the OBB file when it's missing. Everything works fine except that the user has to restart the game (kill the app, relaunch) in order for the Unity runtime to recognize the OBB is present. This manifests itself as an error in trying to load the next scene which would reside in the OBB.

    We've implemented an app 'kill and relaunch' functionality but it doesn't always work 100%. In some cases, Unity still fails to recognize the OBB. As a result, we are losing 11% of the users who install and launch the game.

    Is there a function we can call on the UnityPlayerActivity or in the C# runtime system to force Unity to re-detect the OBB presence?

    Thanks.
     
  2. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    835
    Does this always happen on certain devices or does "some cases" mean that randomly it could fail on the same device that it has worked before? Do you have read external storage permission added to the manifest? Some devices / os versions need that permission granted to be able to load OBB files.
    There is no such method, but Unity player tries to load OBB files after it has been resumed. So killing the player should not be necessary, sending it to the background and resuming should be enough, or launching another activity and then returning to Unity player should work as well. Basically anything that pauses Unity player should work for this.
     
  3. unity_cf8op2urKKw1iw

    unity_cf8op2urKKw1iw

    Joined:
    Aug 26, 2019
    Posts:
    3
    I've recently added the OBB downloading functionality to my game as well. I can second what ChricKCK posted, after downloading the OBB file from Google Play and trying to launch the second scene, either:

    A. Without pausing the app, the first scene of the game keeps reloading indefinitely.
    B. Pausing the app and resuming it does something, but it results in the screen becoming black, the second scene does not load though.

    There are no errors in the logcat at any point of this process. Only after restarting the game does Unity recognize and load the downloaded OBB file.

    Tried playing with READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions, but that didn't change anything.

    Interesting note - deleting the OBB file while the game is running doesn't seem to interrupt the game? Is everything kept in memory, or is it cached when the game starts? If so, maybe that is where the problem is? If Unity doesn't find an OBB file when the game starts, maybe it just forgets to update the cache?