Saving input from user in series of scenes

I have 3 scenes that have identical layout. They have same script on “Save” button that takes saves input written by user in InputField. When the user comes back to the scene, they can view the text they had written. Here’s the script:

  • public InputField inputText;
  • string text;
  • void Start()
  • {
  • text = PlayerPrefs.GetString(“Score”);
  • inputText.text = text;
  • }
  • public void getInput()
  • {
  • text = inputText.text;
  • PlayerPrefs.SetString(“Score”, text);
  • }

}

However, if I save something in one scene, say - “I’m at Activity1”; it shows up in the next scene as pre-loaded input. So far, I’ve tried following workarounds but they don’t seem to work. 1. Create a new script for particular scene with identical code. 2. Create an object of playerPref class, but the object does not have SetString function of playerPref class.

Eg. private PlayerPrefs Activity1; Activity1.(the function is missing).

Please let me know how to resolve my issue. Thanks.

Check out this official video on persistence. I refer back to it often. It’s really informative, and would help a lot in your situation.

1 Like
using UnityEngine.SceneManagement;
PlayerPrefs.SetString(SceneManager.GetActiveScene().name+"_Score" ,text);

Keep in mind that the amount of text you can save in one PlayerPrefs entry is limited, but for your score it should be fine.

Yup. Works. Thanks fffMalzbier.