Skip to main content
Search our knowledge base

NullReferenceException

Comments

17 comments

  • Marcos A. Soto Cora

    Great.... Thanks!

    0
  • Louis Mg

    Hello, i've got the same issue but i don't want to put a "Find" function with a name. So i can use it with multiple objects. 

    Is it possible with "this" ? I tried but i still get the error at myOutline.enabled=false;

     

    0
  • Cameron Smith

    Thank you!

    0
  • Jeremy

    In case anyone attempts this and it STILL doesn't work, let me recommend what worked for me.

    I was attempting to get an initiative value out of a Timeline script on my Units in a turn-based tactics game.

    But the Timeline is not directly ON the Unit, but on the initiative button that will be moving along the timeline UI element. It's down in Unit > Canvas > InitButton.

    For a situation like this, where you're setting up complex objects like a file structure, you can dig in to the specific script using GetComponentInChildren. The regular GetComponent won't find your script, because it's not directly on that containing "folder" object.

    2
  • Loladdwa12 Kais12

    Thanks NO HATE

    -1
  • Jacobsc

    I looked up this error and got here... but that is literally how my code is already written as. 

     

    GameObject.FindGameObjectWithTag("RedCube").GetComponent<Renderer>().enabled = false;

    4
  • FrannPV

    @Jeremy thanks dude, it's a super dumb "error" but it was the error. For some reason if you test the game in preview it works without "InChildren" but when built it was needed and i was keep getting the error without knowing what could it be. And it was that... It would be good if Unity adverts or something about it.

    -1
  • Ernest Caballero Lloris

    This saved my life.

    -1
  • Daniel

    Bolt no longer works in any way not even in a new project. I've uninstalled unity bolt and reinstalled and everything.  It still comes up with fixing compiling errors?

     

    -1
  • Vaibhav Pathak

    This error also arises when you have used the script somewhere in game, but forgot to add it to a gameObject which is using it. So for example in my case I was working with a shooter game in which the fire projectile object was using the script but i forgot to add it. SO YES check it out for your game. 

    5
  • Only Games

    O Thank You So Much Sir. It Worked For Me. I was getting this error from long time but now after trying your solution it really worked. Oh Yeah

    0
  • Daniel Brown

    Thank you!  I didn't realize you could just double click the error message to take you to the line of code that was the issue.  

    0
  • Saqib Ali

    Thank You so much Sir

    0
  • Nikolay

    Thank you bro!

    0
  • Dinotamer80

    Had this problem... had. Turns out the save was just corrupted. There goes multiple hours of my life trying to fix what was not broken.

    0
  • Piotr Świerk

    Hi there,

    You can try moving GetComponent from Start() function to Awake() function.

    It worked for me in case of this Error.

     

    0
  • Dimitri Rhamy

    how do i fix this in bolt tell me or give me a link or something i have spent hours just trying to figure this out i am new to unity and it is stressing me out

    -1

Please sign in to leave a comment.