Search Unity

PlayerPrefs IndexedDB format

Discussion in 'Web' started by Fizzer, May 4, 2017.

  1. Fizzer

    Fizzer

    Joined:
    Nov 16, 2016
    Posts:
    40
    Hello,

    I have several players of my WebGL Unity game that get the "PlayerPrefsException: Could not store preference value" error when my game attempts to write into PlayerPrefs.

    The game worked for them at first, but now it fails with this error every time, so I suspect that perhaps they ran out of IndexedDB space.

    I want to see what's using up all the room. Unfortunately, PlayerPrefs doesn't have any ability to enumerate them directly, so I started investigating the IndexedDB database.

    This javascript code can be used to enumerate the IndexedDB database:

    Code (JavaScript):
    1. var initOpenReq = indexedDB.open('/idbfs')
    2. initOpenReq.onsuccess = function() {
    3.     var db = initOpenReq.result;
    4.     var objectStoreName = 'FILE_DATA';
    5.     var transaction = db.transaction(objectStoreName, 'readonly');
    6.     var objectStore = transaction.objectStore(objectStoreName);
    7.     objectStore.openCursor().onsuccess = function (event){
    8.         if (event.target.result){
    9.          
    10.             var s = event.target.result.value;
    11.             console.log(event.target.result.key + " contents=" + (s.contents ? s.contents.length : "none"));
    12.             event.target.result['continue']();
    13.         }
    14.     };
    15. };
    This prints out:

    idbfs/c3ee3b769ea802c1b50dec6084feeab5/PlayerPrefs contents=29953

    In this case I see nearly 30k bytes of data assigned to the PlayerPrefs key, and I can get the data. However, as this is just a big byte array, I'm not sure how to read it.

    Is there any guide or info on how to understand this format? How can I enumerate the PlayerPrefs keys and see how much space each one is taking up?

    Thank you!
     
  2. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    I'm also trying to work this out.
     
  3. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Not exactly what you are looking for but you could have a look at the content of IndexedDB via browser devtools (firefox: Storage=>IndexedDB, Chrome: Application=>IndexedDB)
     
  4. Fizzer

    Fizzer

    Joined:
    Nov 16, 2016
    Posts:
    40
    Won't that just give you the same byte array that the above Javascript did? How do we turn those bytes into keys/values?
     
  5. bodyloss

    bodyloss

    Joined:
    Sep 14, 2017
    Posts:
    1
    It is utf8 encoded binary in a Uint8Array. You can get the text contents by running new TextDecoder("utf-8").decode(s.contents);

    Unfortunately that's not very useful at all. I've been trying to read that in when running in C# and de-serializing it back to a PlayerPrefs, but to no avail.