Search code examples
visual-studiodebuggingvisual-studio-debugging

Is it possible to record variable changes?


I am using Unreal Engine 4 and there is a bug where the mouse is not constrained to the window.

I am trying to debug the mouse position, but it am not sure how I would do it.

Every time I set a break point at the mouse position visual studio will pause the application, it is just really hard to debug because there are so many pauses.

I am wonder if it is possible to record variable changes? For example set a special break point at a variable and visual studio will only very briefly pause the application, look at the variable and put the value into a list.

I could just log the mouse position, but I want to get away from using log all the time.


Solution

  • This can be done by using the "When Breakpoint is Hit" window. Set the breakpoint, right-click it and choose "When hit..."

    enter image description here

    On this window, check both the "Print a message" and the "Continue execution" checkboxes. Then update the string you want to print to include the value(s) that you want printed (variable values and expressions needs to be wrapped in {} to be interpreted as such. Setting "Continue execution" makes the debugger not break at the line, instead, it will just log and continue. The messages are printed to the Debug >> Output window at runtime.

    enter image description here