- Home /
Catching double-clicking console messages
We are using a custom DebugUtils class which provides some nice tweaks such as filtering messages by person or type.
The problem is that when you double click the console window, it makes Mono load up the DebugUtils class/function and not the original calling script.
Can anyone suggest a solution or direction to look into that will make double clicking one of these messages go to the orignal script?
Cheers!
Answer by iwHiteRabbiT · Mar 12, 2015 at 03:15 PM
I had the same problem, then I just made a simple DLL (with Mono) with this unique static class :
using System;
using UnityEngine;
namespace [MyNameSpace]
{
public static class MyDebug
{
public static string TAG = "MyUnity";
public static string CurrentClass
{
get {
var st = new System.Diagnostics.StackTrace();
var index = Mathf.Min(st.FrameCount - 1, 2);
if (index < 0)
return "{NoClass}";
return "{" + st.GetFrame(index).GetMethod().DeclaringType.Name + "}";
}
}
public static void Log(string Msg)
{
if (Debug.isDebugBuild)
Debug.Log(string.Format("{0}:{1}:{2}", TAG, CurrentClass, Msg));
}
public static void LogWarning(string Msg)
{
Debug.LogWarning(string.Format("{0}:{1}:{2}", TAG, CurrentClass, Msg));
}
public static void LogError(string Msg)
{
Debug.LogError(string.Format("{0}:{1}:{2}", TAG, CurrentClass, Msg));
}
}
}
Then, back in Unity you just have to past your plugin.dll in your asset folder and in the code side:
using [MyNameSpace];
// In method
MyDebug.Log("My message log");
In the console you will see: "MyUnity:{ClassName}:My message log" And if you dbl click on it you will open the ClassName file at the right line!
It works like a charm!
Do you know if this still works? I tried this on Unity 2017.3.0f3 and it didn't work, then updated to 2018.2.0b4 and still haven't had any luck.
@$$anonymous$$aezin I just tried it and it did work (U2018.2.3f1).
Thanks for the verification. I took another look at it and this was a problem due to me placing my dll's pdb in the Assets folders ins$$anonymous$$d of just the dll. That generated a mdb file, which I assume then caused Unity to try to debug my plugin.
I resolved my issue by deleting the pdb and mdb files and now everything works great.
Answer by ianjosephfischer · Jan 12, 2013 at 09:33 AM
I've been working on something like this. I can open the external editor at the correct spot, but I am searching for something that will let me set the console double click goto position.
Here is my code for that which gets called by my internal debugging system. If you found out how let me know or if any one else has any tips.
private static void OpenFile()
{
Assembly assembly = Assembly.GetAssembly(typeof(UnityEditor.SceneView));
System.Type type = assembly.GetType("UnityEditorInternal.InternalEditorUtility");
if(type == null)
{
Debug.Log("Failed to open source file");
return;
}
string[] stackFrames = System.Environment.StackTrace.Split(new char[] {'\n' });
string callingFrame = stackFrames[4];
string[] splitLog = callingFrame.Split(':');
char drive = splitLog[0][splitLog[0].Length-1];
string filePath = splitLog[1];
splitLog[2] = StringManipulation.TrimStartString(
splitLog[2], "line ");
int lineNumber = int.Parse(StringManipulation.GetBeforeNextChar(
splitLog[2], '\n'));
string fullDrive = drive + ":" + filePath;
//Debug.Log(@fullDrive + " line #" + lineNumber );
MethodInfo method = type.GetMethod("OpenFileAtLineExternal");
method.Invoke(method, new object[] { @fullDrive, lineNumber });
}
(Here is that "StringManipulation" method I use which I am sure you could have figured out if you are reading this question.
public static string GetBeforeNextChar(string sourceString, char trimed)
{
string[] splits = sourceString.Split(trimed);
return splits[0];
}
public static string TrimStartCharacter(string sourceString, char trimed)
{
sourceString = sourceString.TrimStart(trimed);
return sourceString;
}
Answer by Inhuman Games · Nov 24, 2013 at 06:12 PM
Our editor console replacement asset has this feature, see the second feature discussed in this video:
Answer by Martin_Gonzalez · May 17, 2019 at 08:48 PM
It has to be a DLL yes or yes? I'm trying this in 2018.3.11 and it opens the MyDebug class
Yes and like $$anonymous$$aezin said, make sure you don't put the pdb/mdb files.