I’m attempting to use Visual Studio to breakpoint inside the C++ code of my Unreal 5 project, which I’ve heard is possible.
I’m using Visual Studio Community 2022.
I have the solution configuration set to DebugGame.
Debug → Attach to Process → UnrealEditor.exe
I’m running the simulation in UE (after attaching to process).
I’m not building Unreal itself from code - just my game project.
Yet, no breakpoints are being hit inside code that I know is being executed.
This breakpoint will not currently be hit. The source differs from the original.
Hover over breakpoint → Settings → Location → Allow source to differ
That eliminated the immediate warning, but did not change the outcome.
That warning means your source is different than what was used in your executable. The file that you have your breakpoint in is not recompiling. Cause could be many things. Maybe you forgot to compile before running. This happened to me once when I forgot a module in the build.cs file. Maybe you moved or renamed the file, etc. Dunno. If you copied the project, but didn’t update the paths, this can happen. Whatever the case, that file has not compiled.
Sometimes, you can have stray UnrealEditor.exe’s that didn’t shut down properly as well.
It sounds like you’re saying I need to compile before attempting to debug. If so, are you referring to building in Visual Studio, Unreal Editor, or both?
Compile in VS. You can’t use live coding AFAIK. If you are compiling, then something is wrong with your setup. Your file isn’t actually compiling and you need to find out why. As @DoDoSophieDoDo says, have you tried DebugGameEditor? That’s what you should use for debugging if you’re using the editor.
If DebugGameEditor still has the same warning and you’re sure it was compiled, then you’re running the wrong exe or you’re editing the wrong cpp file or something got out of sync. Make sure the cpp file is actually the one you think it is. Also make sure you don’t have a copy of the cpp file in the same project folder. VS could be using the source from the wrong sub folder.
Have you tried rebuilding your project?
This has nothing to do with UE. It’s all about the project settings in VS for DebugGame and DebugGameEditor. If you haven’t changed those settings in VS, then something is out of sync. Have you updated .net lately?
How are you running the editor? Are you running it from VS? If not, why not?
While investigating your advice, I closed and re-opened both UE and VS, and now it suddenly works. I know I had tried restarting them previously, but I hadn’t tried closing and reopening the already-open cpp files. I wonder if the ones I was viewing were from a different clone of the repo.
To answer your questions:
Make sure the cpp file is actually the one you think it is.
Yep, that was it.
Have you tried rebuilding your project?
Yes. Right click project → Rebuild.
Have you updated .net lately?
No.
How are you running the editor? Are you running it from VS? If not, why not?
This one confused me a little. I start UE from windows, and then usually go to “Tools → Open Visual Studio”. Sometimes I’ll start both from windows to save time, since they both take several minutes to boot up, if I know I’ll need them. How would one go about opening UE from VS?
You just click the big green play icon (it should say Local Windows Debugger). This way you don’t need to attach or do anything to debug. If you want to run it in release mode (after choosing “Development Editor” , click the other play button that just has the outline (isn’t filled in).
edit: You can give yourself the solution. You found it.