How to add a new module to a plugin?

Posted once before on the “Engine Source & GitHub” Topic, reposted without tagging because that topic seems inactive.

Hi, this is incredibly frustrating because I can’t find any useful ressources about this issue, yet I know it’s been done before. I have a very simple problem : I’ve written a runtime plugin and now I want to add an editor module to it so I can create some custom UI elements to help navigate the plugin.

Someone asked this same question back in 2017 but the thread is not very helpful. Doing some more sleuthing online I’ve found this stream, which briefly shows the directory structure of a plugin with a runtime module and an editor module, which is exactly what I want.

So I set up the new directory structure for my Plugin, modified the .uplugin script to include my new module, and added some source files and Build.cs so it can actually compile. But I have a few problems:

  • The EditorModule.cpp file doesn’t recognise its corresponding EditorModule.h file
  • Despite that, the solution can compile without errors
  • However, UE4 crashes when I open the project.

This is the crash message:
Assertion failed: IsValid() [File:C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\Core\Public\Templates/SharedPointer.h] [Line: 890]

Some extra notes:

  • If I remove the new module from the plugin.uproject file, unreal doesn’t crash anymore, so the problem is definitely the new module
  • I’ve tried doing:
#include "../Public/EditorModule.h"

instead of:

#include "EditorModule.h"

in the module’s cpp file, and now the header gets recognised. However the other issues remain.

  • I also tried removing everything and starting from scratch while having UE4 open, then compiling the plugin inside UE4 and doing “refresh visual studio project files” afterwards. UE4 doesn’t crash immediately, and everything compiles correctly. However the new module’s functionality isn’t there and after closing and opening the project it crashes again.

Now I don’t know what to do. I’ve looked at the Build.cs files, I’ve looked at the .uplugin file, I’ve looked at the Target.cs files… I’m out of ideas. Can someone please help?

Did you ever figure this out?