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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Need help for a basic decision (loading textures at runtime)

Discussion in 'General Graphics' started by JoergLange, Oct 22, 2015.

  1. JoergLange

    JoergLange

    Joined:
    Oct 22, 2015
    Posts:
    21
    Hi folks,

    in my project during runtime I download jpg-files from the web and I have to store/cache those textures for later use.

    I worked out two methods. First method: I download the files an store it into the persistent data path. Later I'm able to grab the jpgs right from there using www (file://).

    Second method: I download the jpgs and do a base64String-Conversion. I'm then able to store those converted picture as a string inside playerPrefs. Later I'm grab the string from the playerPrefs again, convert it back into byte and load it into the texture.

    So the basic question: storing the jpgs as strings in playerPrefs or "as it is" in the persistent data path?

    Which methode is better regarding memory or performance (the project should run on Mac/PC as well as on tablets/smartphones).

    Thanks in advance!
     
  2. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    525
    I'd say it depends on the size of the images and the platform limitations you're under... Storing them as encoded strings in playerprefs is definitely not going to be faster than storing them as files, and it won't do much for saving up in file sizes either.. In fact, IIRC, the playerprefs database was limited to 1MB storage total, IDK if that has changed though, that was the case a couple years ago.

    I'd use normal files, unless you can't do that for some reason (platform restrictions?).

    Cheers
     
    JoergLange likes this.
  3. JoergLange

    JoergLange

    Joined:
    Oct 22, 2015
    Posts:
    21
    Thank you. Yes, I came (with your help) to the conclusion to store it as files into the persistent data path. Could be possible that the pics are >1MB from time to time and you're right, there is a Limit under some circumstances (Windows - Registry - per playerprefs-key). It's a bit more work to manage the files in the data path but thats okay. I've found a way to encode the jpgs with a simple XOR-operation so if a user finds the persistent data path, he will not able to use/copy the pictures (it may be material with copyright restrictions, because of that a "caching" on a device is a bit complicated).
    It's not planned for the first release but it's quite possible that the program will be released for iPad/Android as well. I suppose, on this devices it's better too, to use the persistent data path? Because of memory issues (I suppose, that whole "storing-pics-into-strings-and-write-or-get-it-to-from-the-playerprefs"-story could be a memory-killer)?

    Cheers