Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Saving from input field with TMPro

Discussion in 'UGUI & TextMesh Pro' started by MRSMITHXXII, Nov 29, 2022.

  1. MRSMITHXXII

    MRSMITHXXII

    Joined:
    Aug 16, 2022
    Posts:
    1
    I am trying to update an project to saving the contents of an input field using TMPro instead of the legacy text. I am getting no errors but nothing is saving. Can anyone explain why the attached code doesn't work?



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using TMPro;
    6.  
    7. public class SaveLoad : MonoBehaviour
    8. {
    9.     public string theText;
    10.     public GameObject ourNote;
    11.     public GameObject placeHolder;
    12.    
    13.     void start()
    14.     {
    15.             theText = PlayerPrefs.GetString("NoteContents");
    16.             placeHolder.GetComponent<TMP_InputField>().text=theText;
    17.      
    18.     }
    19.    
    20.  
    21.   public void SaveNote()
    22.   {
    23.         theText=ourNote.GetComponent<TMP_Text>().text;
    24.         PlayerPrefs.SetString("NoteContents", theText);
    25.  
    26.   }
    27.   }