Search Unity

Feature Request Link to the gameobject that caused the error

Discussion in 'Editor & General Support' started by TiggyFairy, Sep 9, 2022.

  1. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    506
    Hello. A lot of my time is spent trying to work out which game object caused an error due to a missing reference or something equally small. Could we have some kind of link in the traceback to the gameobject that caused the error? It would be massively helpful.

    Also, is there a way to stop auto refresh firing during playmode? I think there should be
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,938
    Debug.Log and similar all have overloads you can use to pinpoint game objects during debugging. If you pass in an object for context, it'll be highlighted when selecting the debug log entry.
     
    TiggyFairy likes this.
  3. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    506
    Thanks, though, I mean, it would help if it would just tell me so I don't have to try and recreate the error. lol
     
  4. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331
    It's not exactly the same, but I've found that just being able to find all instances of the class that threw the exception in the open scenes helps a lot in debugging.

    console-find-instances.gif

    In many cases you only have one instance of the class in the hierarchy anyways, and in the other cases this at least helps you quickly get the list of possible culprits.
     
    TiggyFairy likes this.
  5. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    506
    That would be really nice. How do I get that?

    EDIT - You made an folders asset that was a feature request I made! Thank you!!
     
    SisusCo likes this.
  6. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    1,331
    It's possible to parse the full name of the type that threw the exception from the stack trace, then use reflection to find the type with a matching name, and then use Object.FindObjectsOfType to find all instances of that type from the loaded scenes.

    I've made a custom Console window with this functionality. It's only currently available as part of the Debug.Log Extensions asset, though I've been meaning to create a standalone version of it at some point...
     
    TiggyFairy likes this.
  7. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    506
    Ah, thank you! I may buy it as I'm often frustrated by lack of obvious info in the console.