Search Unity

Null Reference Exception Error in PacMan AI

Discussion in 'Navigation' started by Raquel_Pendragon, Apr 7, 2021.

  1. Raquel_Pendragon

    Raquel_Pendragon

    Joined:
    Apr 20, 2020
    Posts:
    11
    Hello! I'm following a very good tutorial on how to make a pac man clone, but I stumbled upon an Null Reference Exception Error: Object reference not set to an instance of an object. You can watch the full video to see the whole code here <
    >. The lines I have trouble are shown at 30.04, but here is the code:

    GameObject GetPortal(Vector2 pos)
    {
    GameObject tile = GameObject.Find("Game").GetComponent<GameBoard>().board[(int)pos.x, (int)pos.y];
    if(tile != null)
    {
    if (tile.GetComponent<Tile>().isPortal)
    {
    GameObject otherPortal = tile.GetComponent<Tile>().portalReciever;
    return otherPortal;
    }
    }
    return null;
    }


    The thing that is bothering me is that teh code works in every pellet, except this one.
    upload_2021-4-7_16-13-5.png
     

    Attached Files:

    Last edited: Apr 7, 2021