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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

NullReferenceException Please Help!!

Discussion in 'Scripting' started by Britulon_6, Nov 11, 2018.

  1. Britulon_6

    Britulon_6

    Joined:
    Nov 11, 2018
    Posts:
    3
    Hello Im new in unity and I have a problem, Im making a collab with a friend and I had the game working but then It suddenly gave me this error and even though I try to restore my previous game, it seems that it still doesnt work. So Ive looked all over the internet and I cant find why this is wrong.
    I have my class GokuHealth, and my class HealthBar, In GokuHealth script theres a public HealthBar called "gokuBar", since HealthBar is Mono:Behaviour You have to instance it through unity (I think so), and I have done that, never the less it stills throws me this "NullReferenceException: Object Reference not set to an instance of an Object"
    There's something that I dont understand also, that like you can see on the images that I uploaded, in GokuHealth script on the GetkeyDown, O and P (THE ORANGE ARROWS on the img), the console throws me an NullReferenceExeception error, but it stills works the gokus healthbar in the game goes up and down and it prints the value of its health.
    Nevertheless on the method on trigger2D it prints "DAÑO" in the console, but it fails to do the rest.
    Please help <3 and sorry for bad english :D
     

    Attached Files:

  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    It would take too long to figure out where the error is by going through all of your scripts.
    Instead, post the exact error message. It will show which line in which script the error is occurring.
     
    Britulon_6 likes this.
  3. Britulon_6

    Britulon_6

    Joined:
    Nov 11, 2018
    Posts:
    3
    It is posted, in INSTANCE img there's the console, with all the problems, I think the main one relies on this
    NullReferenceException: Object reference not set to an instance of an object
    GokuHealth.Start () (at Assets/Goku/Scripts/GokuHealth.cs:9)
    that image has 0 views lol
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    You should probably rename the GokuHealth Start method to Awake. I don't have time to test what I'm saying, but I think this is an initialization issue. So it's just a tip.
     
  5. Britulon_6

    Britulon_6

    Joined:
    Nov 11, 2018
    Posts:
    3
    Tried it, throws the same error.
    NullReferenceException: Object reference not set to an instance of an object
    GokuHealth.Awake () (at Assets/Goku/Scripts/GokuHealth.cs:9)
     
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    Well, then I have no idea without build your entire code and go through step by step and insert debug log around the problem. Which you can do easily.