Create Custom engine classes for your game module

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 so...

Updated 8 months ago Edit Page Revisions

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://forums.unrealengine.com/t/what-is-the-proper-method-for-extending-the-editor-engine/282885/14 for it.

Extending the editor engine

https://forums.unrealengine.com/t/what-is-the-proper-method-for-extending-the-editor-engine/282885/14

How to Include files from another module

https://forums.unrealengine.com/t/how-to-include-files-from-another-module/285523

Linking error when exporting component

https://forums.unrealengine.com/t/linking-error-when-exporting-component/280972/3

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

https://forums.unrealengine.com/t/how-can-i-set-up-multiple-modules-so-that-they-can-interact/282603/4