When I start up the game, I have an NPC Character, which has a script attached called NPCController
When I click “z” to “Interact” With this character, this error shows up. Feel free to ask me more questions, Thanks.
NullReferenceException: Object reference not set to an instance of an object
NPCController.Interact () (at Assets/Scripts/Characters Controller/NPCController.cs:13)
PlayerController.Interact () (at Assets/Scripts/Characters Controller/PlayerController.cs:64)
PlayerController.HandleUpdate () (at Assets/Scripts/Characters Controller/PlayerController.cs:49)
GameController.Update () (at Assets/Scripts/GameController.cs:58)
In all of these scripts, there is a line of code that has “Interact”
"NPCController script goes as shown -
public class NPCController : MonoBehaviour, Interactable
{
[SerializeField] Dialog dialog;
public void Interact()
{
DialogManager.Instance.ShowDialog(dialog);
}
}
And it is not happy with these lines in PlayerController
This If statement is in a public void method called HandleUpdate()
if (Input.GetKeyDown(KeyCode.Z))
Interact();
And this If statement is in the void “Interact”
if (collider != null)
{
collider.GetComponent<Interactable>()?.Interact();
}
And its also not happy with this in my game controller script
void Update()
{
if (state == GameState.FreeRoam) playerController.HandleUpdate();
else if (state == GameState.Battle) battleSystem.HandleUpdate();
else if (state == GameState.Dialog) DialogManager.Instance.HandleUpdate();
}