So I'm trying to get a script of mine to pass information to another static class being used for saving files as I've been told I wouldn't want that script to be instantiated. So I used a separate script to get input field text. However, I seem to be encountering a problem whenever I want to save the file.
I keep getting the error "Object reference not set to an instance of the object", I have made done this though. (See code below)
The class to get the name of the file
public class SaveInputField : MonoBehaviour
{
public static string saveName;
public GameObject inputField;
public void getFileName(string saveName)
{
saveName = inputField.GetComponent<Text>().text;
Debug.Log("Save file name: " + saveName);
SaveFile.saveName = saveName;
}
}
^called whenever its been edited
The static class
public static class SaveFile
{
public static string saveName;
public static void SaveData(Deck deck)
{
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + "/" + saveName + ".dd";
FileStream stream = new FileStream(path, FileMode.Create);
Debug.Log("Stream Opened");
DeckData data = new DeckData(deck);
formatter.Serialize(stream, data);
stream.Close();
Debug.Log("Stream Closed");
}
```
saveName = inputField.GetComponent<Input>().text;
Sorry I forgot about that part \$\endgroup\$