Am I getting stale binaries?

I’ve been encountering this problem over and over again while developing in Unreal. I’ll write a bit of code, compile in visual studio, run the game in editor and my changes don’t appear to take. In the past when I’d encounter this problem, I’d close everything, delete my cache folders (Intermediate, Binaries and Saved), regenerate Visual Studio project files, compile in Visual Studio and then open Unreal Editor, hit play and my changes would take.

This fix is a long process and it’s incredibly frustrating. I found today that just closing the editor and reopening it works as well, but I can’t be certain it works for all cases. Should I not be building my game from Visual Studio and only be building from Unreal Editor? Is building in Visual Studio only helpful for finding syntax errors?

Ok let me explain how code compilation with UBT works may clear things up for you.

So UE4 don’t use default build system in VS, it used is own UnrealBuildTool which can be run from anywhere (well VS tools can be called outside too) and it just use VS compiler. So in VS project have special NMake that runs UBT and editor also call it the same, there generally should not be difference which you use. Now when editor is open UBT build in Hot Reload mode regardless where do you doing, it creates 2nd dll for you code module in binaries and when he is finished it tells editor to reload to new dll to new version but it does not deletes old version, so each time oyu hot reload it creates new dll to binaries. When you close editor UBT builds normally but first thing it checks if there is any hot reload dlls in binaries and delete them. Intermediate forder contains VS project files (which gain don’t effect work of UBT) and object files which is output of compilation of individual cpp files which later is linked, they stay there so they don’t need to be recompiled all the time and compile object files only to files that changed.

So you dont need to delete Intermidiate and aspecially you should not delete Saved as you clearing local project configuration and you may lose something, delete it only as last resort when configuration may be fault.

Hot Reload is not perfect, some of engine code is not prepared for things to be hot swapped in memory and create random strange behaviors. If that happens just close editor and compile in VS with editor closed and UBT will clean up. If you find something reproducible raport it as bug so Hot Reload can improve

There also really rare cases that object files may pass linking process but creates bogus code inside the dll which may create random strange crashes, you also may have random unexplained linking errors, then all you need is rebuild which will clean all object files. If this does not fix then delete intermidiate and regenerate project files

The VS bugged errors is InteliSense confused by some hackery used in UE4 code, most impotently generated code from UnrealHeaderTool, it know issue ever since 4.0 and guide even recommend to disable Errors tab back then because it has lot of misleading things. Lot of people say VS Assist is better with dealing with UE4, but personally didn’t use it so not sure how good it is, but people say it is.

Thank you for the quick answer. I feel like this insanity has finally come to an end. Do you know why UBT doesn’t delete the old binaries and object files? Wouldn’t that force the editor to look for the fresh binaries and object files when the project is run again?

I don’t really know, maybe for safety reason swap requires both old and new dlls to exist. As for object files already explained, for you rebuild might be nothing but if you deal with huge project you have ton of code compilation can take minutes, so object files will always stay and you need consent to clean it, this is standard procedure in any C++ project (outside UE4) and any build system.

I had a feeling it was to keep something like swam agent from crashing. Is that what you meant by swap?