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

Update Resources folder when the game is started

Discussion in 'Scripting' started by herbie, Jan 28, 2014.

  1. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    My Android game uses a lot of small images. These images are in the Resources folder.
    When the game needs an image, it's loaded from the Resources folder. That's working perfect.

    What I would like to have is that every time when the game is started, it checks if there are new images on a specific website (using WWW) and load the new images into the Resources folder on the Android device. Is that possible?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, since files in Resources are not really files; once Unity makes a build everything is combined into assets. You can download images as external files though.

    --Eric
     
  3. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Ok thanks.
    What I have now is that the game loads the image from a website when he needs it. But the problem is that you always need an internet connection and that you sometimes have to wait when the internet connection is slow. Using the Resources folder is a nice solution for that.
    But sometimes there will be new images available for the game so I need a way to update. I'd rather not want to update the whole game with all images but only add the images that are new. Is there a way to to that?
     
  4. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
  5. damian.doroba

    damian.doroba

    Joined:
    Apr 4, 2013
    Posts:
    36
    You can create asset bundles, put them into StreamingAssets folder and retrieve via WWW class.

    Code (csharp):
    1.  
    2. WWW www = new WWW(System.IO.Path.Combine(Application.streamingAssetsPath, assetBundleName));
    3. AssetBundle bundle = www.assetBundle;
    4.  
     
  6. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Thanks.

    Asset bundles are new for me and I have a (noob) question.
    Is it right that everytime that the game is started, the asset bundle must be downloaded into the memory of the device?
     
  7. damian.doroba

    damian.doroba

    Joined:
    Apr 4, 2013
    Posts:
    36
    It has to be loaded into memory.
    WWW class hides complexity of downloading file - if this file already exists on phone, it simple use local version.