Object Reference not set to an instance? Unity 2d Platformer Issues

Hey! so i’m trying to make it so that when my character falls in the void or touches spikes (both have the tag “FallDetection”) that the sprite moves back to it’s original position. but it doesn’t seem to work. I get the errors: “Object reference not set to an instance of an object” & “the name ‘PlayerSprite’ does not exist in the current context”

This is my playermovement code, which holds the death stuff too.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PlayerMovement : MonoBehaviour {

    public CharacterController2D controller;
    public Animator animator;

    public float runSpeed = 40f;

    float horizontalMove = 0f;
    bool jump = false;
    bool crouch = false;

    // Update is called once per frame
    void Update () {

        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

        if (Input.GetButton("Jump"))
        {
            jump = true;
            animator.SetBool("IsJumping", true);
        }

        if (Input.GetButtonDown("Crouch"))
        {
            crouch = true;
            animator.SetBool("IsJumping", false);
        } else if (Input.GetButtonUp("Crouch"))
        {
            crouch = false;
        }

    }

    //is called when object lands
    public void OnLanding ()
    {
        animator.SetBool("IsJumping", false);
    }

    //is called when object uses crouching input
    public void OnCrouching (bool isCrouching)
    {
        animator.SetBool("IsCrouching", isCrouching);
    }

    void FixedUpdate ()
    {
        // Move our character
        controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
        jump = false;
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if ( collision.tag == "FallDetection") {
        PlayerSprite.transform.position = new Vector3(1, 0, -10);
        }

        if ( collision.tag == "Finish") {
        SceneManager.LoadScene ("LevelMenu");
        }

    }
}

FYI: This is not a post for the 2D forums, it’s a post for the Scripting forums because it’s about you trying to understand C#, not 2D features.

You’re reporting two different things. The first is you’re referring to something that isn’t set to anything so it’s NULL and the error will tell you which line that is (you don’t report it) so go ahead and set it to something.

The second is that I also don’t see “PlayerSprite” defined anywhere either so where should it be?

In the end, it just sounds like you’re following a tutorial so I would suggest going back to the original tutorial and go over the code again.