Debugging Build.cs scripts

Hello,

I’d like to debug some of my build scripts to better understand what happens. Since it’s code, I expect to be able to put a breakpoint and step through the execution.

I couldn’t figure out how to do it. Do you have any guidance?

Thanks !

Hi,

To debug UBT (your Build.cs) file, you would:

  • In VS, set UnrealBuildTool program as your default program.
  • In VS, set the ‘Debug’ and ‘Win64’ target
  • In VS, right-click on UnrealBuildTool project -> Build
  • In VS, right-click on the UnrealBuildTool project -> Properties -> Debug -> Open debug launch profiles UI
    • Enter the UBT command line arguments. (You can find them in the logs when you build) Ex: -Target=“LyraEditor Win64 Development -Project=D:\UE_5.6\Samples\Games\Lyra\Lyra.uproject”
  • Edit/touch the build.cs you want to debug. I believe UBT caches some outputs to avoid re-running everything. By touching the file (add a space/save), it forces UBT to run the code again and hit your breakpoints.
  • Start UnrealBuildTool in debug (F5).

In my case, I also had to go VS -> Tools -> Options… -> Debugging -> General and uncheck ‘Require source files to exactly match the original version’ to hit the breakpoint for my project.

[Image Removed]

Let me know how it goes.

Regards,

Patrick

Thanks a lot Patrick, I was able to debug a Build.cs script thanks to your instructions.

My particular issue was that I am using Rider with the EzArgs plugin which tries to replicate the UnrealVS UI for passing arguments to the program, but I discovered that it only works for C++ programs. Still your answer was very useful in confirming how I should proceed.

Hi,

I’m glad you were able to figure this out. By the way, you can also add logs to the .cs file, UBT will recompile automatically. I often do that for small quick checks because it’s usually faster than debugging. Something like:

System.Console.WriteLine("==================== Log Something =======================");Regards,

Patrick

Thanks for the suggestion ! This is great

As a side note, I’ve had issues with breakpoints not setting in those .cs files because of inconsistent line endings, and the way UBT reads the files to dynamically compile them.

The fix is to use ReadAllBytesAsync instead of ReadAllTextAsync in ParseSyntaxTreeAsync:

[Image Removed]

Cheers,

Lambert

Thanks Clara, I shared the info to UBT developer.

Regards,

Patrick

FYI: JIRA created (UE-313099). We are going to take a look at this issue with line ending and probably take your proposed fix.