Search Unity

Null Reference Exeption game pausing

Discussion in '2D' started by pokemontybor, Jun 14, 2019.

  1. pokemontybor

    pokemontybor

    Joined:
    Jun 11, 2019
    Posts:
    8
    my game pauses and the error log says
    NullReferenceException: Object reference not set to an instance of an object
    AreaExit.Start () (at Assets/Scripts/AreaExit.cs:36)

    then when I double click it it brings me to

    I highlighted the part that it highlights

    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    using UnityEngine.SceneManagement;





    public class AreaExit : MonoBehaviour

    {





    public string areaToLoad;

    public string areaTransitionName;

    public AreaEntrance theEntrance;




    // Start is called before the first frame update

    void Start()

    {

    theEntrance.transitionName = areaTransitionName;

    }



    // Update is called once per frame

    void Update()

    {



    }



    private void OnTriggerEnter2D(Collider2D other)
    {
    if (other.tag == "Player")
    {

    Debug.Log("Collisiondetected,TryingtoLoad");

    SceneManager.LoadScene(areaToLoad);

    PlayerController.instance.areaTransitionName = areaTransitionName;
    }

    }

    }
     
  2. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    the errors says that theEntrance is not set, which would mean check your editor parameters that you have set the variable
     
  3. pokemontybor

    pokemontybor

    Joined:
    Jun 11, 2019
    Posts:
    8
    I am sorry but I am noob so i dont understand
     
  4. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    In the unity editor (where you place your objects on the scene etc), find the AreaExit script in your scene (you should know where you put it), and in the Object Inspector (usually on the far right, tells you properties of components) you will see all your public parameters for the script, such as areaToLoad, areaTransitionName and theEntrance. Make sure that theEntrance is set to something (not None/Null),