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:
var initOpenReq = indexedDB.open('/idbfs')
initOpenReq.onsuccess = function() {
var db = initOpenReq.result;
var objectStoreName = 'FILE_DATA';
var transaction = db.transaction(objectStoreName, 'readonly');
var objectStore = transaction.objectStore(objectStoreName);
objectStore.openCursor().onsuccess = function (event){
if (event.target.result){
var s = event.target.result.value;
console.log(event.target.result.key + " contents=" + (s.contents ? s.contents.length : "none"));
event.target.result['continue']();
}
};
};
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!