0

I want to do something, and for some reason I get an error:

NullReferenceException: Object reference not set to an instance of an object

Player:

    public GoTo sentFrom;
    private void Update()
    {
        transform.eulerAngles = new Vector3(0, 0, 0);
        if (transform.position.y < -5)
        {
            sentFrom.GoToAuto("YouDied", "tuturial1");
        }
    }

GoTo:

    static public string WentFrom;
    public void GoToAuto(string to, string from)
    {
        WentFrom = from;
        SceneManager.LoadScene(to);
    }

Thank You :D

Slomg
  • 45
  • 1
  • 8
  • You didn't provide relevant definitions for classes such as `GoTo`, but if I had to guess, you never created an instance of `GoTo` when declaring `sentFrom`. So `sentFrom.GoToAuto(...)` is not set to an instance of `GoTo`, hence the object reference error. This error always has to do with referencing an object that has not been instantiated. Try `public GoTo sentFrom = new GoTo();` – h0r53 Feb 10 '20 at 16:23
  • Please refrain from applying tags to your questions that don't apply. This isn't C, and read the Visual Studio tags: " DO NOT use this tag on questions regarding code which merely happened to be written in Visual Studio." –  Feb 10 '20 at 16:33

0 Answers0