Solution
The issue is the difference between Text Mesh Pro InputField and the native InputField. I was using TMP which seems to be different when referencing it. I reverted to native Inputfield and it worked immediately.
Original Error
I am trying to save the text from an inputfield into a variable to use across scenes. Currently I cant even get it to save the text alone as I get a null-reference. Ive tried multiple solutions and nothing is working. Using the exact same examples from YouTube and other online sources.
I have also tried using PlayerPrefs.SetString / GetString with no real luck.
Current Setup is as follows.
- Script below collects and saves the text to a public variable. Script is attached to empty GameObject
- InputText is associated to the text part of the inputField When pressing Start I get the null reference.
- Start button simply calls the "SaveAddress()" Function
Error Message
NullReferenceException: Object reference not set to an instance of an object
SaveTipBotAddress.SaveAddress () (at Assets/Scripts/SaveTipBotAddress.cs:25)
Text Scripts
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SaveTipBotAddress : MonoBehaviour
{
public string ilpAddress;
public GameObject inputText;
public void SaveAddress()
{
ilpAddress = inputText.GetComponent<Text>().text;
}
}