Hi everyone,
I am building a WebGL Multiplayer Game that utilizes Photon PUN. I have a Player Name script set up, and attached to a UI so players can enter their name upon joining the game. When I test the game, the UI works up until I press the “join” button where I then receive a pesky NullReferenceException error. This is strange because there are no visible issues in the script when I open it in Visual Studio.
The error reads as follows :
NullReferenceException: Object reference not set to an instance of an object* *PlayerNameInput.SetUpInputField () (at Assets/PlayerNameInput.cs:23)* *PlayerNameInput.Start () (at Assets/PlayerNameInput.cs:15)* *
My Player Name script looks like this :
* *using UnityEngine;* *using UnityEngine.UI;* *using TMPro;* *using Photon.Pun;* *public class PlayerNameInput : MonoBehaviour* *{* *[SerializeField] private TMP_InputField nameInputField = null;* *[SerializeField] private Button continueButton = null;* *private const string PlayerPrefsNameKey = "PlayerName";* *private void Start() => SetUpInputField();* *private void SetUpInputField()* *{* *if (!PlayerPrefs.HasKey(PlayerPrefsNameKey)) { return; }* *string defaultName = PlayerPrefs.GetString(PlayerPrefsNameKey);* *nameInputField.text = defaultName;* *SetPlayerName(defaultName);* *}* *public void SetPlayerName(string name)* *{* *continueButton.interactable = !string.IsNullOrEmpty(name);* *}* *public void SavePlayerName()* *{* *string playerName = nameInputField.text;* *PhotonNetwork.NickName = playerName;* *PlayerPrefs.SetString(PlayerPrefsNameKey, playerName);* *}* *}* *
Can someone help me figure out what is causing this?
I can’t find anything in my other scripts that may be interfering with this one,
and I’ve already assigned the objects / interactions in the inspector. I’m not sure what else to do.