Search Unity

Excluding a method frame from stack trace in Debug.Log()?

Discussion in 'Scripting' started by frosted, Jul 29, 2014.

  1. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Is there any way to do this?

    The use case is stuff like a throw helper, where you toss an exception or log item from some method but you don't want that call to show up in the stack trace.

    Here's another example:
    Code (csharp):
    1.  
    2. public static class GameObjExtension{
    3.   public static void Log( this MonoBehaviour mono, String msg ){
    4.     Debug.Log( mono.gameObject.name + ":" + msg );
    5.   }
    6. }
    7.  
    8. .... usage like:
    9. public class ABC : MonoBehaviour{
    10.   public void Awake(){
    11.    this.Log( "include my game object's name in the log automatically" );
    12.   }
    13. }
    14.  
    But when you click the log item in the editor, it would jump to ABC's Awake call not GameObjExtension.

    Is there like a MethodImpl tag or something tricky and hidden?
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287