- Home /
PlayerPrefs not saving mission info at all.
Hello I know there are questions like this out there but based on everything I have seen I am not doing anything incorrect however while all the info is being hit correctly checked by both debug statements and stepping threw the code with the debugger when i go to load its as if nothing saved it all comes back to the default value. I have read many answers and I have gone threw unity's forums stack overflow and any piece of information I could find but I just can't seem to get this to work. I have other things in the program saving correctly with no issues I honestly am just not finding where I am going wrong and my employer is getting impatient. I need another set of eyes please any help would be greatly appreciated I have included the functions being called as a whole but I can provide more if needed.
Thanks;
public void SaveMission(string airlineName){
Debug.Log("Saving mission " +airlineName + MissionName+"CompletedTime "+TimeCompleted.ToString());
PlayerPrefs.SetString(airlineName +MissionName+"CompletedTime",TimeCompleted.ToString());
//Save if the mission was completed
if(IsMissionCompleted){
Debug.Log("Saving mission as complete");
PlayerPrefs.SetInt(airlineName + MissionName+"IsComplete",1);}
else{
Debug.Log("Saving mission as incomplete");
PlayerPrefs.SetInt(airlineName + MissionName+"IsComplete",0);}
Debug.Log(PlayerPrefs.GetInt(airlineName + MissionName+"IsComplete"));
PlayerPrefs.Save();
}
public void LoadMission(string airlineName){
//load the time that the mission was completed
Debug.Log("Loading mission " +airlineName +MissionName+"CompletedTime "+TimeCompleted.ToString());
string tempdate = PlayerPrefs.GetString(airlineName +MissionName+"CompletedTime");
//load if the mission was completed
int tempbool = PlayerPrefs.GetInt(airlineName + MissionName+"IsComplete");
//convert values to the proper type
if(tempdate != ""){
TimeCompleted = DateTime.Parse(tempdate);
}
else{TimeCompleted = DateTime.MinValue;}
Debug.Log(tempbool.ToString());
if(tempbool == 1){
IsMissionCompleted = true;
}
else{
IsMissionCompleted = false;
}
}
Your code seems to work, i tried the following and it printed out
"That AirlineSpace LaunchCompletedTime 6/28/2015 10:18:59 P$$anonymous$$"
"Saving mssion as complete"
"1"
"Loading mission That AirlineSpace LaunchCompletedTime 6/28/2015 10:18:59 P$$anonymous$$"
"1"
using UnityEngine;
using System;
public class NewBehaviourScript : $$anonymous$$onoBehaviour {
string $$anonymous$$issionName="Space Launch";
bool Is$$anonymous$$issionCompleted=true;
DateTime TimeCompleted=DateTime.Now;
void Start () {
Save$$anonymous$$ission("That Airline");
Load$$anonymous$$ission("That Airline");
}
public void Save$$anonymous$$ission(string airlineName){
Debug.Log("Saving mission " +airlineName + $$anonymous$$issionName+"CompletedTime "+TimeCompleted.ToString());
PlayerPrefs.SetString(airlineName +$$anonymous$$issionName+"CompletedTime",TimeCompleted.ToString());
//Save if the mission was completed
if(Is$$anonymous$$issionCompleted){
Debug.Log("Saving mission as complete");
PlayerPrefs.SetInt(airlineName + $$anonymous$$issionName+"IsComplete",1);}
else{
Debug.Log("Saving mission as incomplete");
PlayerPrefs.SetInt(airlineName + $$anonymous$$issionName+"IsComplete",0);
}
Debug.Log(PlayerPrefs.GetInt(airlineName + $$anonymous$$issionName+"IsComplete"));
PlayerPrefs.Save();
}
public void Load$$anonymous$$ission(string airlineName) {
//load the time that the mission was completed
Debug.Log("Loading mission "+airlineName+$$anonymous$$issionName+"CompletedTime "+TimeCompleted.ToString());
string tempdate=PlayerPrefs.GetString(airlineName+$$anonymous$$issionName+"CompletedTime");
//load if the mission was completed
int tempbool=PlayerPrefs.GetInt(airlineName+$$anonymous$$issionName+"IsComplete");
//convert values to the proper type
if(tempdate!="") {
TimeCompleted=DateTime.Parse(tempdate);
}
else { TimeCompleted=DateTime.$$anonymous$$inValue; }
Debug.Log(tempbool.ToString());
if(tempbool==1) {
Is$$anonymous$$issionCompleted=true;
}
else {
Is$$anonymous$$issionCompleted=false;
}
}
}
Thank you at least I know I am not going crazy lol but I still need to figure out why its not working for me I will have to look somewhere else like in the function calls thank you for your help! and if I find out what the issue is I will post it.
Your answer
Follow this Question
Related Questions
Saving and load from player prefs in Unity3D on mobile devices?? 0 Answers
Problems with Playerprefs script 1 Answer
Saving Scenes and loading GameObjects? 4 Answers
How to efficiently hand out rewards based on the level that the player completed? 3 Answers
Saving & Loading the scene (or at least one array) via Javascript 1 Answer