Search Unity

Attempting to make a clicker game running into Null ReferenceException.

Discussion in 'Scripting' started by eznukezilla, Sep 29, 2019.

  1. eznukezilla

    eznukezilla

    Joined:
    Jan 29, 2018
    Posts:
    2
    Hi, I am making a simple clicker game as a side project right now but my scripts aren't properly identifying public floats.
    GameManager Script:
    upload_2019-9-28_18-48-15.png
    upload_2019-9-28_18-49-11.png


    On button press script.
    upload_2019-9-28_18-47-39.png
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Can you post the full error message? Which line does the error occur on and in which file?

    If any of your public component fields aren't assigned, you will get a NullReferenceException when you try to use them. Check that your
    GameManager GM
    variable is set in the inspector for your
    Fight
    component, as well as all your
    Text
    components, in the
    GameManager
    .
     
  3. Synpse

    Synpse

    Joined:
    Mar 19, 2018
    Posts:
    20
    That's not enough information for us to help you but you most likely forgot to assign a a value to one of your public variables. Either that or you have the reference assigned and you then lose it, either because it was destroyed or lost its reference for some reason.
    You should check if everything is properly assigned and see exactly what the error is because it actually tells you the line where the error is happening.