I have a (otherwise perfectly working) projects that will not compile in-editor. More exactly it compiles, but the editor crashes immediatly after compiling. I did not launch the game or start PIE, this happens when simply pressing the “Compile” button.
Compiling from VS2013 is OK, running is OK, wether in PIE or Launch.
I redid the test, the Initialize method is called twice (once when starting, a second time after compiling) and Shutdown is never.
Shutdown is supposed to be called from the FProjectname::ShutdownModule() method, and it is really called when I exit the game cleanly, so I don’t get it.
Okay, I’ve tried this with the ShooterGame sample and it does look like a bug.
Basically FModuleManager::AbandonModule doesn’t call ShutdownModule; I’m not 100% sure that it should, so I’m going to check and get that confirmed one way or the other.
As a workaround, AbandonModule does broadcast a ModulesChangedEvent with ModuleUnloaded as the reason, so you could hook in to that event and unload your style from it.
The following code should do that for you (replace ProjectName with the name of your game module).
void FProjectName::StartupModule()
{
// ...
FModuleManager::Get().OnModulesChanged().AddSP(this, &FProjectName::HandleModulesChanged);
}
void FProjectName::ShutdownModule()
{
// ...
// This will probably still be an issue as this won't get called when the module is abandoned, so you may end up with multiple delegates trying to unload your style. You may have to add a bool to guard against that in HandleModulesChanged.
FModuleManager::Get().OnModulesChanged().RemoveAll(this);
}
void FProjectName::HandleModulesChanged( FName ModuleThatChanged, EModuleChangeReason::Type ReasonForChange )
{
static const FName ProjectName("ProjectName");
if(ModuleThatChanged == ProjectName && ReasonForChange == EModuleChangeReason::ModuleUnloaded)
{
FSUIResources::Shutdown();
}
}
I have the exact same issue as Gwenn, and this solution has not resolved my issue. In fact, it made it worse: instead of crashing on compile, it crashes on editor load I have tried recompiling from the command line, to no avail.
I’ve entered an internal bug regarding this issue, so hopefully it will get triaged soon.
Regarding the workaround I provided, how is it crashing? We use a similar method internally to handle some intermodule dependencies in the editor (which is where I lifted that code from).