Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

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.   }