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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Seeing what variable causes a null?

Discussion in 'Editor & General Support' started by Mytts, Apr 29, 2016.

  1. Mytts

    Mytts

    Joined:
    Jun 10, 2015
    Posts:
    10
    When I get a nullpointer exception it can be really frustrating, because usually there are multiple variables referenced on one line. So I was wondering if there are any way to make unity tell me the name of what variable causes the nullpointer?
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,673
    You must use debugger in this case - MonoDevelop or Visual Studio (+Visual Studio tools for Unity), there you can enable exceptions on which the debugger should break, you'll be able to see then what variable is null.
     
  3. Mytts

    Mytts

    Joined:
    Jun 10, 2015
    Posts:
    10
    Is this really the best option? I remember when getting a null pointer in GameMaker (At leat back when I used it) it would say something like: 'Nullpointer exception, variable 'foobar' is null', which made it really fast and nice to debug. Is there really no option to do something like this with Unity?
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,673
  5. Mytts

    Mytts

    Joined:
    Jun 10, 2015
    Posts:
    10
    Thank you very much for your help ^^