Search Unity

Null Reference Excetion

Discussion in 'Getting Started' started by GeorgeA7299, Jan 1, 2019.

  1. GeorgeA7299

    GeorgeA7299

    Joined:
    Apr 8, 2017
    Posts:
    32
    Hello

    I am trying to program a point-and-click advenrture game. I am receiving an error on the following script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.  
    6.  
    7. public class GameManager : MonoBehaviour
    8. {
    9.  
    10.     public static GameManager ins;
    11.  
    12.     [HideInInspector]
    13.     public Node currentNode;
    14.    
    15.     //very bad singleton
    16.  
    17.     void Awake()
    18.     {
    19.         ins = this;
    20.     }
    21.  
    22.     void Update()
    23.     {
    24.         if (Input.GetMouseButtonDown(1) && currentNode.GetComponent<Prop>() != null)
    25.         {
    26.             currentNode.GetComponent<Prop>().loc.Arrive();
    27.         }
    28.     }
    29. }
    Specifically I am getting the error:

    NullReferenceException: Object reference not set to an instance of an object
    GameManager.Update () (at Assets/Scripts/GameManager.cs:26)
     
  2. Well? Have you checked the "loc" if it contains anything? I'm guessing that is the culprit here.
     
  3. GeorgeA7299

    GeorgeA7299

    Joined:
    Apr 8, 2017
    Posts:
    32
    Thank you so much Lurking-Ninja. It worked like a charm.
     
  4. Deleted User

    Deleted User

    Guest

    It would be nice to see what you are making
     
  5. GeorgeA7299

    GeorgeA7299

    Joined:
    Apr 8, 2017
    Posts:
    32
    I your appreciate your response thenewkg82, but my question has been answered.Thanks again.
     
    Last edited: Jan 2, 2019