Make changes to code without restarting editor?

Hi all, I am very new to Unreal Engine. I am a bit confused as I have completed the first lesson in programming for the engine. My issue is: When I make a change in visual studio to my classes, I must close the editor, build the solution in visual studio, then re-open the editor for changes to be applied. I’ve tried using “compile” in the editor but changes are not reflected. When I try to build in VS while editor is open, build fails. Any help will be greatly appreciated. Thanks in advance.

Sorry about that! What sort of change did you make that was not reflected? There are some limitations to this feature currently that we hope to resolve in the future. One of the limitations that we’re going to fix is that construction functions are not re-applied after a Recompile.

–Mike

Hey Mike, thanks for the reply. I am doing a simple AddOnScreenDebugMessage to display a string to the screen like shown in getting started here. When I change the MyNumber value, Visual Studio fails to rebuild unless I close out UE4 editor, then build in vs, re-open UE4, then the change shows. It just takes so long to not only build, but to close and open the editor for small changes like this.

Okay, this is a known limitation that we are working on for a future release.

Good news! There is an easy workaround!

Instead of compiling using Visual Studio, please click the “Compile” button on the editor toolbar. That will automatically save your code and initiate a compile right from within the editor, and automatically reload your changes afterwards.

We are still working on support for “hot reload” from within Visual Studio. Keep an eye out in future releases!

–Mike

Well I was doing the compile inside of the editor as well, trying to figure it out on my own, but that makes changes only to my FString variable. It will not reflect changes to any int32, uint32, float or double unless I do the whole closing UE4, recompiling in VS, opening UE4 again, which takes like 2 or 3 minutes just to make a change or add a single variable. And if I make any change whatsoever to a header file, same consequence. This really puts a damper on productivity for me. I’d just use Blueprint, but I’d rather code. Not complaining, just putting out my constructive criticism. I know it’s still a WIP. Are you guys planning on packaging a preset coding environment rather than just releasing an extension that requires VS Pro? It’d be cool not to have to pay so much money for VS just to code in Unreal properly. It would also be nice not to have to wait so long for references to be imported to VS every time you want to add a new class. I understand these should probably be asked as separate questions though, they just had to do with the issue I’m having. I’ll wait for future release, whenever that may be, thank you for the assistance.

If you are making some new functions you have to close the editor and build it from VS, but if you are only editing some existing function just compile from the Unreal Editor toolbar…

Yeah it doesn’t work lol. I posted a comment below the accepted answer but I guess it got removed or is in moderation or something. I’m only trying to change values, not anything in the header files, I know I can’t make changes to generated code while editor is open. Compiling via the toolbar only updates my FString values, not int32, uint32, double or float.

That is really strange. We’re not able to reproduce this here yet. Can you reproduce this in one of the sample games that have C++ code? If so, please let us know. I’ll keep testing it.

–Mike

As a workaround for now, I had right click on my Actor in the hierarchy and replace it with itself after compiling. I’m guessing that old actors keep old values, so they must be replaced after changes and recompilation. It’s kind of weird that strings update but ints don’t if I don’t do it this way, but this sure beats restarting the engine every time I want to test changes.

I can reproduce this. In case it’s relevant, this is my environment:

  • OSX 10.9.2
  • XCode 5.1

I was working through this programming guide: Unreal Engine CPP Quick Start | Unreal Engine Documentation

If I change the on-screen debug message text value and recompile from within the editor, the changes take. However, if I change the int32 value in XCode and then recompile in UE4, the number remains the same until I replace the actor.

In the example tutorial, the MyNumber assignment occurs in AHelloWorldPrinter::AHelloWorldPrinter(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP); if I reassign the value in void AHelloWorldPrinter::BeginPlay(), the new value is displayed. It appears the Constructor is not called again after the in-editor recompile unless the actor is replaced.

I apologize if any of this was confusing. I’m brand new to Unreal and C++.

You have to close the Editor only if you add new Classes, Functions, Properties or other C++ code with attributes(macros) such as UCLASS() and UPROPERTY(). This is because these attributes add reflection abilities to the Classes, Functions or Properties. In order for the Editor to refresh itself and be able to use the reflected new C++ code, it needs to restart. However, if you add any C++ code without attributes(macros) you can freely compile in VS and it will compile successfully. You simply say “I don’t want the Editor to be aware of the new C++ code I just wrote”. Unfortunately this way you won’t be able to call a function in a Blueprint for example, because the function is not reflected and the Editor doesn’t know that such a function exists. You won’t be able to use any code in the editor, but that doesn’t mean that the code won’t do it’s job. I personally like the Blueprint scripting, but I prefer to do everything from code (Call me an old-school guy :D). Anyway, this is how I understand this concept, so I may not be entirely right.

You can learn more about the attributes(macros) in this blog post and how they add reflection abilities to the C++ code.

Is there a solution, bug number, or trello task for hot reloaded building from Visual Studio?

Hi guys,

Any news about hot reloading after compiling cpp in VS/Xcode? My situation now looks like this:

  1. Create empty project, adding to game mode:
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("HELLO WORLD"));
  1. Press compile in editor button, run, see HELLO WORLD text

  2. Updating code in XCode

    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT(“UPDATED”));"

  3. Compile in XCode

  4. Run in editor, see HELLO WORLD text

  5. Restart the editor, run, see HELLO WORLD text

  6. Press compile in editor button, run, see UPDATED text

I have a dream to compile in IDE, return to editor and press play. Is that actual direction of engine development?