How to solve UE4 requiring multiple compiles despite saying "Compile succeeded"?

Sometimes I’ll click compile and it will say “compile completed” but it still uses old code until I hit compile again. Has anyone been able to solve this?

Here’s an example of what happens:

 Add a log to print "hello world"
 Click compile
 UE4 says "compile completed"
 Click play
 Log is not printed
 Click compile again
 UE4 says "compile completed"
 Click Play
 "hello world" is logged

Expected behavior:

Add a log to print "hello world"
Click compile
UE4 says "compile completed"
Click Play
"hello world" is logged

Any help is appreciated, thanks. I’m on version 4.22.3

Are we talking about the “Compile” button in blueprints? If so, this seems like odd behaviour. Is this a c++ or blueprint project?

No matter what, first step is always to delete intermediate and binaries folder of project and see if this helps.

I’m talking about the compile button at the top of the UE4 editor. The one used to compile the whole project. It is a C++ project.

I have deleted the intermediate and binaries folder of the project and it still happens. Seems to happen more often if I change a header file. I’ll have to play with it some more to see if I can make it happen consistently. Seems like it’s more like 1/10 compiles will use the previous code, not the new code.

If you make changes to the header file, by adding a new function, changing some signature, adding a new class, struct and such, the most reliable method is still to close editor → compile → reopen editor.

Yeah, that would probably work. It’s just really slow to iterate like that. I think I’d rather press the compile button twice every time than close and reopen the editor. I’m going to see if 4.25 has the same issues.

I usually compile in the editor and if that doesn’t work, I compile in VS. And if that also fails, then I close/compile/open.

Yea after some years with this engine I have simply grown accustomed to closing the editor and restart from visual studio when writing c++ code. I can’t count the amount of times I have had weird behavior due to compiles not working as expected.

One positive side effect of doing this is that you will write more considerate and more consistent code, you simply can’t afford the mistakes :smiley: Eventually you will write code free of bugs without a single recompile!

If I know that the changes I have made is quite minimal, contained in ONE module, and does not involve thirdparty dlls and such, I am fairly confident in doing a hotreload of that module specifically. I remember a long time ago (4.14 or something), the Compile button was completely broken and never worked. Since then I have stopped using it.

Hope this answers your questions :slight_smile:

After some more testing, 4.25 has the same issue. I don’t know if my exact steps are reproducible, but it is frequently happening during this Unreal tutorial I’m following. Even the tutorial videos include the issue in it.

Thanks for the reply. Yeah, it just makes it tedious to learn. In the beginning mistakes are very frequent, which means crashes are too. But I can live with it. The engine is really cool. I’m still able to get by just fine. Thanks. It also just makes it hard to learn because I can’t know for sure if I made a mistake or if my compile just didn’t go through.

Try compile in Visual Studio iot should trigger Hot Reload too

I really wanted the UE4 compile button to work, but it doesn’t always work, and worse when I was using it, UE4 would crash unexpectedly and I would lose significant amounts of work, or wedge my project so it wouldn’t even open in the editor :frowning:

I don’t ever use the Editor compile button anymore, because it’s not safe to use it in all cases.

I picked up this habit from watching UE4 C++ courses on Udemy that all compile from VS then start the editor. Now, from VS, I start the editor from f5 to debug, then hard stop the editor from VS to recompile. It’s less work, because it’s fewer problems than hot-reloading.

Epic does not do a good job of communicating this. It’s unfortunate UX they put the “compile” button front and center on the main toolbar when it is a dangerous and unreliable feature that requires special consideration.