Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'Editor & General Support' started by polymur, Dec 19, 2020.

  1. polymur

    polymur

    Joined:
    Dec 18, 2020
    Posts:
    7
    so im having a problem this appears when ever a grenade exploads in my game the effect just keeps going up when it happens how can i fix this
     
  2. si0ty

    si0ty

    Joined:
    Jun 28, 2019
    Posts:
    24
    Hey, first of all: You should always give more information about your problem / game so people can figure out what's going on. Try to share some of the code your working on.

    At first sight, the Null reference error has nothing to do with movement. This error appears when your code is not exact enough and unity can't find what you want to reference.

    BUT: When a null reference occurs the code after it is not executed. This can lead to additional malfunctions and seemingly different problems. If the null reference error is okay and will be set later on you can set a condition like this:

    if(!"your missing reference") {
    // code here executes even when there is no reference found
    }

    If the null reference error is not intentional: Make sure it's referenced by publicly set it in the inspector or just track it down where it's missing a set it up private:

    "youre missing reference" = "reference"

    Null Reference Errors are a problem every beginner runs into but it's 100% always some small mistake maybe even a typo which leads to it.