Unreal Plugins and Hot Reload

by on

We're making a couple of games and I was copying the code from one project to the other, and it seemed like that needed to change.

Decided to make a plugin for all the boilerplate stuff, like startup screens, login menu, main menu, options menu, HTTP APIs, etc.

Got everything converted into a plugin, got the plugin working with the project files in the first project.

Then I wanted to really get rid of everything I was doing in the Blueprint graph for the Widgets since most of that was going to be used in all games as well and it's just so much cleaner and easier to read when logic is in C++.

Hit the Compile button and bam error, thought maybe it was a function I was overriding but after some quick searches, it seems(ed) that Hot Reload of plugins is just not supported.

I began to accept that as fact, then randomly I tried to build in Visual Studio and it worked!

However, if you try to compile within the Unreal Editor after you make changes to your plugin code before compiling in Visual Studio it will error out, so lesson learned.

When compiling changes to your plugin, build in Visual Studio and then if you look in your console window in the Unreal Editor if the Hot Reload didn't happen on the module you wanted it to you can hit the compile button in the Unreal Editor again and you should be golden.

If you have more than one project using plugins is a great way to stop repeating yourself, copying code and widgets were definitely going to lead to an error at some point.

Keeping all the boilerplate logic and widgets independent from game logic and content is definitely nice. 

When setting up your button callbacks and what not in C++ I recommend using the bool Initialize() override; in your header.

Then in the .cpp I do this:

bool UMyWidget::Initialize()
{
    if (Super::Initialize())
    {

        /* Initialization stuff here */

        return true;

    }

    return false;

}

 

Although, I'll probably change that to this:

 

bool UMyWidget::Initialize()
{
    if (!Super::Initialize()) return false;

    /* Initialization stuff here */

    return true;

}

 

I should also mention that Initialize is called when in the editor as well so you should check for a game instance to see if that game is running or not before calling things that won't be instanced until the game is running if you're doing any of that.

My new implementation is:

bool UMyWidget::Initialize()
{
    if (!Super::Initialize()) return false;

    if (!GetInstance()) return true;

    /* Initialization stuff here */

    return true;

}

 

GetInstance() is a function that returns a pointer to the custom game instance or NULL and is available to all of my widgets from my base subclass user widget.

Hopefully, this is helpful for you!


Comments 0
No comments have been left yet.