UE5 Variable is optimized away and not available when debugging

In this tutorial, we cover a debugging scenario where you will get the optimized variable message in the visual studio debugger when trying to watch variables. This hinders the debugging process as the developer can not see the variables he needs to troubleshoot.

Temporarily Turn Optimizations Off

Code optimizations are great because they speed up your code but the trade-off is less debugging information. To disable code optimizations for unreal engine code you need to turn them off at the module level. We do this in the build.cs

 

Go to your module’s build.cs and add this line:

 

OptimizeCode = CodeOptimization.Never;

 

This will disable code optimization for that module and you should be able to see all variables when debugging code in that module. Remember to comment out or remove the line when publishing or when done debugging.

5/5

Gamechanger plugin for notehighway rhythm games and music visualizers

5/5

Add Text and 2D UMG widgets to Level Sequences

Consider investing in some of our plugins. They might save you some time.  Also helps supports these tutorials.

Instantly get access to our plugins like Blender Curves Importer and UMG Cinematics and more when  you support us on Patreon!

 Join Us On Discord For More Daily Tips!