Course contentsShow
← Unreal Engine Game Development
Lesson 65 of 8801. Foundations and Editor WorkflowFree lesson

Exposing Plugin Logic to Game Modules

Establish clean interfaces between your plugin and the main project using public header files and module-specific API macros for cross-module communication.

In this lesson, you will learn how to bridge the gap between your self-contained Plugin and your main Game Module so that they can communicate safely and efficiently.

When you create a plugin, it lives in its own isolated world. By default, the game project cannot "see" the classes or functions inside your plugin's source code. To fix this, we use API Macros. These macros tell the Unreal Build Tool which parts of your plugin are "Public" (exported) and which are "Private" (hidden).

Defining the API Macro

Every plugin has a header file generated in the Public folder, usually named YourPluginNameModule.h. It contains a macro that looks like this:

#define YOURPLUGIN_API __declspec(dllexport) // Or dllexport depending on platform

When you mark a class with this macro, you are giving the rest of the engine permission to link against it.

Exposing Classes and Functions

To expose a class from your plugin to your game project, you simply insert this macro before the UCLASS() or class keyword:

// Inside MyPluginPublicClass.h
class MYPLUGIN_API UMyPluginPublicClass : public UObject
{
    GENERATED_BODY()

public:
    // This function is now accessible to your Game Module
    void PerformPluginAction();
};

By adding MYPLUGIN_API (using the specific name generated for your plugin), you effectively mark that class as "Public."

Connecting the Modules

Even with the macro, your Game Module needs to know your plugin exists. You must open your game project’s Build.cs file and add your plugin name to the PublicDependencyModuleNames list:

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

Once the dependency is added, your Game Module can include the public headers from your plugin, and the compiler will successfully link the two together. This separation keeps your code clean—you only expose the "Public" interface while keeping your complex implementation details hidden inside "Private" folders.

Key Takeaway: Use your plugin’s unique API macro to mark classes for export and add your plugin to the Game Module’s Build.cs dependencies to establish a formal bridge between the two.