Loading error when using PlayerPrefs.GetInt with WebPlayer

Hello

Something really odd happens with my game in the version distributed for webplayer (this does not happen in the PC version).

The game starts with a menu, then pressing New Game fires a function which uses PlayerPrefs.getInt to see if the player has already played the game and a “currentLevel” value has been stored in their PlayerPrefs.

Now, whenever I clear my webprefs, simulating a user with no prefs saved then the game only loads part of the scene, part of the textures, basically a broken scene with only part of what should be there. It’s as if it starts loading the scene but then something breaks the process (an exception?).

However, after loading the scene my game automatically saves the currentLevel value with playerPrefs.setInt, thus creating a playerpref file on the machine. The following time the game is played everything is right.

Now what’s happening here? I tried catching any execptions that may happen when the game is trying to retrieve the player pref like so:

var prefs : int;

//deal with any errors
try{
	prefs = PlayerPrefs.GetInt("currentLevel");
} catch (err){
	prefs = 0;
}

Does this ring a bell for anyone? Thanks in advance for any help!

Could it be the 1M limit for Web Player prefs? PlayerPrefs are not size limited in stand alone versions, but have a 1M limit per Web player URL.

Thank you Dakwamine, I did consider using the getInt() version with the defaut value. But then I came across this solution which has solved the problem fortunately:

//deal with PlayerPrefs not existing on machine
if(PlayerPrefs.HasKey("SaveGame")){
	prefs = PlayerPrefs.GetInt("SaveGame");
} else {
	prefs = 0;
}

The error is no longer happening, with or without the URL Prefs on the machine!