PhotonView is not set?

Options
Hi.
I'm working a Escape menu so whenever someone pressed escape, it shows this menu. When they click "Continue Game" i want the menu to disappear but it throws back an error

NullReferenceException: Object reference not set to an instance of an object
PlayerMenuManager.Esc_ContinueGameBtn () (at Assets/Scripts/PlayerMenuManager.cs:42)

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.Characters.FirstPerson; public class PlayerMenuManager : MonoBehaviour { public bool EscMenuOpen; private GameObject SceneCanvas; private GameObject EscapeMenu; private PhotonView PhotonView; private void Start() { PhotonView = GetComponent<PhotonView>(); if (PhotonView.isMine) { SceneCanvas = GameObject.Find("Screen"); EscapeMenu = GameObject.Find("PlayerMenuManager/EscMenu"); SceneCanvas.SetActive(true); EscapeMenu.SetActive(false); EscMenuOpen = false; } } private void Update() { if (PhotonView.isMine) { if (Input.GetKeyDown(KeyCode.Escape) && EscMenuOpen == false) { this.gameObject.GetComponent<FirstPersonController>().enabled = false; SceneCanvas.SetActive(false); EscapeMenu.SetActive(true); EscMenuOpen = true; Cursor.visible = true; } } } public void Esc_ContinueGameBtn() { if (PhotonView.isMine) { this.gameObject.GetComponent<FirstPersonController>().enabled = true; SceneCanvas.SetActive(true); EscapeMenu.SetActive(false); Cursor.visible = false; EscMenuOpen = false; } } }

Answers

  • Aberidius
    Aberidius
    edited November 2017
    Options
    -.
  • Hi @Aberidius,

    since I don't know the format of your source code, can you please tell me which of the above line 42 is? On this line a NullReferenceException occurs, means that the object / component, you want to work with, doesn't exist or you don't have a valid reference to it. To check this, you can either Debug.Log the affected object / component or attach the Debugger, add a breakpoint and check if the object / component is null.