Create Custom engine classes for your game module

From Epic Wiki

Introduction

Creating, custom Engine classes is actually very easy, and there is not much work needed. Why would you want to create custom Engine class ? It's useful, when you need to initialize some data before game or editor will be loaded, during engine initialization, so that data will be accessible after game starts.

Adding Classes

To get started you will need to add two new classes to your project. Note the "U" prefix, which is required for any non-Actor UCLASS. An actor uses "A":

#include "Engine.h"
#include "YourGameEngine.generated.h"

UCLASS()
class UYourGameEngine : public UGameEngine
{
	GENERATED_BODY()
}

and

#include "UnrealEd.h"
#include "YourGameEditorEngine.generated.h"

UCLASS()
class UYourGameEditorEngine : public UUnrealEdEngine
{
	GENERATED_BODY()
}

Along with standard blank implementation in CPP files.

Add UnrealEd dependency

In your Build.cs file, you will find PublicDependencyModuleNames. Add UnrealEd in it, like this:

PublicDependencyModuleNames.AddRange(
    new string[] { 
        "Core", 
        "CoreUObject", 
        "Engine", 
        "InputCore", 
        "UnrealEd"
    });

Edit DefaultEngine.ini

Now you need to edit DefaultEngine.ini in your project config folder. Open file and add these lines:

[/Script/Engine.Engine]
GameEngine=/Script/YourModuleName.YourGameEngine
EditorEngine=/Script/UnrealEd.EditorEngine
UnrealEdEngine=/Script/YourModuleName.YourGameEditorEngine

That is it! Now when you compile and run you project, new classes will be used.

If you're creating a custom editor engine, there are some more set-ups that need to be done to ensure a proper building of both game and editor. Refer to https://answers.unrealengine.com/questions/41509/extending-editor-engine.html for it.

UE4 Answer Hub Related posts

Extending the editor engine

https://answers.unrealengine.com/questions/41509/extending-editor-engine.html

How to Include files from another module

https://answers.unrealengine.com/questions/54681/how-to-include-files-from-another-module.html

Linking error when exporting component

https://answers.unrealengine.com/questions/31640/linking-error-when-exporting-component.html

How can I set up multiple modules so that they can interact? (theoretical explanation)

https://answers.unrealengine.com/questions/39838/classinterface-multiple-modules-confusion.html