So Unity has this feature where, when you double click on a warning/error that you fired in code, it jumps you to the line in code. I like that! But, I send all my warnings through a system I wrote, so I can be like "LogMessage(eSeverity.Low, eCategory.Rendering, “You’re rendering things off-screen!”); and not have it actually output to Unity if I don’t care about that at the moment.
As a result, double-clicking a warning jumps me to the line in my message-logging code that says “if (severity >= thresholdForThisCategory) { UnityEngine.Debug.LogWarning(str); }”. Which isn’t really useful. Can I make double-clicking, like, always go to the line 2 items up the call stack?
tomes, that was just what I needed, thanks. If anyone else sees this, I implemented the last answer in that link (make a separate DLL) (also make sure to target .net 3.5 framework to make Unity happy) and it works like a charm.
To further help anyone who’s trying to do the same as I did, here is a README.md I created to walk through the steps for creating a .dll within VSCode for Unity. Goodluck!
Building a Dynamic Link Library in Visual Studio Code
This walk-through has been largely copied from [Create a .NET class library using Visual Studio Code - .NET | Microsoft Learn](http://# Building a Dynamic Link Library in Visual Studio Code This walk-through has been largely copied from Create a .NET class library using Visual Studio Code - .NET | Microsoft Learn, but has been adapted to better address the steps for Unity Projects. Note, if a solution file and a class library project has already been skipped, open the .sln file (as seen in the first couple of steps) then proceed to the steps under Building the class library project. ## Create a Solution 1. Start Visual Studio Code. 2. Select File > Open Folder… (Open… on macOS) from the main menu 3. In the Open Folder dialog, create a new folder (this will be the name of the .sln file) and click Select Folder (Open on macOS). 4. Open the Terminal in Visual Studio Code by selecting View > Terminal from the main menu. The Terminal opens with the command prompt in the solution folder. 5. In the Terminal, enter the following command: dotnet new sln The terminal output looks like the following: The template "Solution File" was created successfully. ## Create a class library project 1. In the terminal, run the following command to create the library project: dotnet new classlib -o NAME_OF_LIBRARY The -o or --output command specifies the location to place the generated output. 2. Run the following command to add the library project to the solution: dotnet sln add NAME_OF_LIBRARY/NAME_OF_LIBRARY.csproj 3. Edit the library targets by opening NAME_OF_LIBRARY/NAME_OF_LIBRARY.csproj and make sure Unity is added (additionally add UnityEditor if needed). In the future you may need to open Unity’s Assembly-CSharp.csproj and copy any fields that may have changed. <Project Sdk="Microsoft.NET.Sdk"> <ItemGroup> <Reference Include="UnityEngine"> <HintPath>C:\Program Files\Unity\Editor\Data\Managed\UnityEngine.dll</HintPath> </Reference> </ItemGroup> <PropertyGroup> <LangVersion>9.0</LangVersion> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> </Project> ## Building the class library project 1. Add and save any files to the project or create any additional class libraries now. 2. Run the following command to build the solution and verify that the project compiles without error. dotnet build The terminal output looks like the following example: Microsoft (R) Build Engine version 16.7.4+b89cb5fde for .NET Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... All projects are up-to-date for restore. NAME_OF_LIBRARY -> C:\...\NAME_OF_PROJECT\NAME_OF_LIBRARY\bin\Debug\netstandard2.0\NAME_OF_LIBRARY.dll Build succeeded. 0 Warning(s) 0 Error(s) Time Elapsed 00:00:02.78 ## Add the .dll to Unity 1. All that Unity needs to run the library files is the newly built .dll as seen from the path above. Thus, drag the .dll from current folder to the Unity project or package folder that needs it. 2. After Unity has compiled the library should be available to be used from within Unity. 3. At this point it is safe to delete all the contents of the library folder(s) that are not specifically the C# files and the .csproj file (i.e. the bin and obj directories).), but has been adapted to better address the steps for Unity Projects. Note, if a solution file and a class library project has already been skipped, open the .sln file (as seen in the first couple of steps) then proceed to the steps under Building the class library project.
Create a Solution
Start Visual Studio Code.
Select File > Open Folder… (Open… on macOS) from the main menu
In the Open Folder dialog, create a new folder (this will be the name of the .sln file) and click Select Folder (Open on macOS).
Open the Terminal in Visual Studio Code by selecting View > Terminal from the main menu. The Terminal opens with the command prompt in the solution folder.
In the Terminal, enter the following command:
dotnet new sln```
The terminal output looks like the following:
The template “Solution File” was created successfully.```
Create a class library project
In the terminal, run the following command to create the library project:
dotnet new classlib -o NAME_OF_LIBRARY```
The -o or --output command specifies the location to place the generated output.
2. Run the following command to add the library project to the solution:
dotnet sln add NAME_OF_LIBRARY/NAME_OF_LIBRARY.csproj```
3. Edit the library targets by opening NAME_OF_LIBRARY/NAME_OF_LIBRARY.csproj and make sure Unity is added (additionally add UnityEditor if needed). In the future you may need to open Unity’s Assembly-CSharp.csproj and copy any fields that may have changed.
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Reference Include="UnityEngine">
<HintPath>C:\Program Files\Unity\Editor\Data\Managed\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup>
<LangVersion>9.0</LangVersion>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>```
## Building the class library project
1. Add and save any files to the project or create any additional class libraries now.
2. Run the following command to build the solution and verify that the project compiles without error.
dotnet build```
The terminal output looks like the following example:
Microsoft (R) Build Engine version 16.7.4+b89cb5fde for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
NAME_OF_LIBRARY -> C:\...\NAME_OF_PROJECT\NAME_OF_LIBRARY\bin\Debug\netstandard2.0\NAME_OF_LIBRARY.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:02.78```
## Add the `.dll` to Unity
1. All that Unity needs to run the library files is the newly built `.dll` as seen from the path above. Thus, drag the `.dll` from current folder to the Unity project or package folder that needs it.
2. After Unity has compiled the library should be available to be used from within Unity.
3. At this point it is safe to delete all the contents of the library folder(s) that are not specifically the C# files and the `.csproj` file (i.e. the `bin` and `obj` directories).
The dll approach doesn’t work for me, because I have not only a customized logger but also a wrapper for the log call in my base class for all scripts.
P.S. I’ll have to deal with the fact that I have to type Logger.Log() instead of Log(), and that I have to work on the Logger in a aseprate solution now, but at least it works and I have the nice logs that show me the caller and the line of code, and they are clickable.
All reflection, no extra arguments. I planned to share this logger on git, when it’s more fleshed out. Whoever wants it, ping me
For anyone looking for an actual working solution in 2024 that doesn’t involve using DLLS!
Someone realized that as long as your custom logger class name ends with “Logger” and your functions start with “Log” that it just works automatically.