Search Unity

Is there a way to tell which instance is throwing an error?

Discussion in 'Scripting' started by Ne0mega, May 19, 2022.

  1. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    755
    I've always just assumed there isn't. But is there a way to tell the specific instance of a component that is throwing an error?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    If you know what line your error is on, you could do something like.

    Code (CSharp):
    1. Debug.Log("ERROR", gameObject);
    This would allow you to click on the debug message and it will flash that gameobject in the scene that sent that message. This might help.
     
  3. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    755
    Hmm, I don't think that will work. My particular issue is/was an index out of range error.
     
  4. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    not sure what ide you use, but if you have it trigger a breakpoint on exception you could easily use your debugging tools to see what the name of the object is, or in the case of riders debugging tools it will just tell you.

    most ide's will let you trigger a breakpoint on all exceptions or a exception type of your choice.