Download

How can I get a debuggable version of my game to load in the editor?

I am still struggling to figure out how to get debugging working with UE4 C++. I have tried running the editor with the -debug flag, but it doesn’t seem to change anything. When I use the editor to compile, the output seems to indicate it is creating a development build, and if I attach the debugger to the editor process and set a breakpoint, some of my local variables are optimized out, making it difficult to step through the code and figure out what’s happening. I can set Visual Studio’s build configuration to Debug Game and build the game project, but the editor doesn’t load that version of the game project. Does the -debug switch actually do anything? What do I need to do to get a debuggable (non-optimized) version of my game classes to work with the editor?

(I also posted this question on AnswerHub a couple of days ago – I wasn’t sure whether it was better to post questions there or here).

So what build target do most people use when doing C++ development, and what methods do you use for debugging? I have had to just spam the output window with the values of all my variables every frame, which is quite cumbersome compared to being able to step through code.

Depending on your needs you can select the target from the VS Drop Down:

DevelopmentEditor
Development
DebugGameEditor
DebugGame
Shipping

Sounds like you might just want to run DevelopmentEditor from VS, then all your breakpoints will hit for example when running in pie…

They key is to launch the editor from VS

Thanks! Starting the editor from VS did the trick. For some reason I had it in my head that I wasn’t supposed to do that. But doing that made it possible to use the DebugGame build, which is exactly what I wanted!

Another trick you can do is put PRAGMA_DISABLE_OPTIMIZATION at the top of the file and PRAGMA_ENABLE_OPTIMIZATION at the bottom of a file for any file you want unoptimized. This way you don’t have to build a whole other configuration and the rest of your code still runs just as fast.