It seems that the way hyperlinks behaves in the editor console has been modified in Unity 6.
In Unity 2021.2 and before you could create your own custom stack trace by using:
Free text<a href="Assets\SourceFileName.cs" line="25">Free text</a>
It work perfectly, when you clicked on the hyperlink it went to Visual Studio at the file and line specified and it even selected the whole line.
Now, in Unity 6, it goes to Visual Studio in the specified file, but it doesn’t go to the specified line and it doesn’t select the line anymore.
I guess that the syntax has change for some reason, does anybody knows how we can achieve the same result as before?
To reproduce the problem, just create 2 files and place each of the following classes in each file:
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;
public class Logging : MonoBehaviour
{
void Start()
{
LogStack1();
}
[MethodImpl(MethodImplOptions.NoInlining)]
public void LogStack1()
{
Common.LogStack2();
}
[MethodImpl(MethodImplOptions.NoInlining)]
static public void LogStack3()
{
String TestLog = "Log example";
StackTrace TheStackTrace = new StackTrace(true);
for (Int32 i=0; i<TheStackTrace.FrameCount; i++)
{
StackFrame CurrentStackFrame = TheStackTrace.GetFrame(i);
String FileName = CurrentStackFrame.GetFileName().Remove(0, CurrentStackFrame.GetFileName().IndexOf("Assets\\"));
Int32 LineNumber = CurrentStackFrame.GetFileLineNumber();
String MethodName = CurrentStackFrame.GetMethod().Name;
TestLog += "\n";
TestLog += MethodName;
TestLog += "() (at ";
TestLog += "<a href=\"";
TestLog += FileName;
TestLog += "\" line=\"";
TestLog += LineNumber.ToString();
TestLog += "\">";
TestLog += FileName;
TestLog += ":";
TestLog += LineNumber.ToString();
TestLog += ")</a>";
}
UnityEngine.Debug.Log(TestLog);
}
}
public class Common
{
[MethodImpl(MethodImplOptions.NoInlining)]
static public void LogStack2()
{
Logging.LogStack3();
}
}