[Help] Variables being shown wrong while debugging

I’m using a clean install of the last version of the Visual Studio 2022, it’s updated and there’s no extra extensions.

But when I try to debug my code, some variables are shown wrong, some Arrays have missed index or half of the information is there, like instead of showing a FVector, show a FVector but with X, Y or Z information missing. And when I add a breakpoint the compiler doesn’t stop there, if I add a UE_LOG, the log is printed, but still the breakpoint doesn’t pause the compiler. Also, the UE_LOG show the correct information, but the debugger doesn’t.

At the beginning the debugger worked as normal, but now I can’t trust the information that it shows

I wonder how are you checking variables content when you can’t set breakpoints? Anyway, as a wild guess, the solution for last problem i comes about was posted here: Increase the Number of Modules Loaded When Attaching the Debugger

1 Like

Well, not all breakpoints was unreachable, but since the solution you linked worked for the breakpoints, I assume that only the “deeper” breakpoints was unreachable.

But sadly I still can’t see most of the variables values, only printing, here’s an example:

Here guideMap is a TMap, in the index 13 there’s half of the information and in the 14 onward there’s no information, but if I print any index, it shows the variable value normal, I just can’t see while debugging.

At some point it start to shows the variables again.

But it keeps fragmenting from time to time.

There’s another bug where it shows the variable as point flutuation value like: “3.3464534E+10” or something like that (I just typed this number randomly) but again, when I print it, it’s normal.

The last one drove me crazy like: “Why I’m getting this value?! I already checked all the code, why?!”

Sadly the breakpoint still not working:

Here the compiler never stop at this breakpoint, but print the “?”. And if I add a breakpoint inside the NextBlock() it stop there.

I don’t know what to do anymore, without the debug is beign hard to fix the bugs, compiler not stopping in the breakpoint, variables with wrong values but print correct values.

Help :frowning:

If you are using anything beyond a debug build with Unreal the code gets optimised, which will produce the issues you are seeing. It very much depends on how the compiler treats the code how easy to debug it will be when optimised.

However to save running debug builds you can just wrap code with some macros - UE_DISABLE_OPTIMIZATION and UE_ENABLE_OPTIMIZATION (or in UE4 PRAGMA_DISABLE_OPTIMIZATION and PRAGMA_ENABLE_OPTIMIZATION). Personally I usually mark the whole file I’m interested in.

If you do that you should be able to use breakpoints and see the relevant variables in the debugger - you may still hit optimised code as you step through if you go to a different file, but just add the macros to that file if needed.

Hope that helps.

How to use it? I tried like this:

UE_DISABLE_OPTIMIZATION

#MY code

UE_ENABLE_OPTIMIZATION

Also tried with Disable/Enabled inverted and didn’t work.I searched for it on google and there’s only 3 links mentioning it, one of then did the same as I did above, but for me it didn’t work.

Tried to change to DebugGame Editor and this partially worked, some variables I can see, like the floating point value now show the value properly, but not the TMap.

For the macros just put them around a function or functions. For those that you’ve disabled optimisation on it should be the same as what you see in a debug build.

What are you seeing in a TMap? Can you see inside a TArray properly?

If you don’t see the members you can try disabling if it’s enabled:
Tools->Options window:
Debugging -> Options -> Debugging -> General -> Show raw structure of the object in variable windows

With “Show raw structure of the object in variable windows” enabled I don’t know where I can find the values, I tried every dropdown menu, but didn’t found it:

And I can see all the TArray values properly (Without “Show raw structure of the object in variable windows”):

image

Those are the same keys that I have in the TMap