If you make the plugin in Unreal itself – I.e., go and create the plugin from the Plugins screen – it will make an API definition for you for the main module the plugin contains.
For instance, I have a plugin called Rooitactics
, which contains my tactical RPG system (grid layout, combat logic, etc.) so that I can reuse it in multiple projects. Within Rooitactics, I have two modules: RooitacticsRuntime
(which is always loaded and contains all my classes and runtime logic and such), and RooitacticsEditor
(which contains the level editor tool that lets me configure tactical settings for a map, as well as tweak the otherwise-automatic grid layout functionality).
To help visualize this, here’s the general directory structure.
<game>
Plugins\
Rooitactics\
Source\
RooitacticsEditor\
Private\
Public\
RooitacticsEditor.Build.cs
RooitacticsRuntime\
Private\
Public\
RooitacticsRuntime.Build.cs
You can see that Rooitactics itself is one plugin which contains those two modules.
Because one of those modules is “RooitacticsRuntime”, the Unreal Header Tool automatically creates a define of ROOITACTICSRUNTIME_API
within that module – basically, the module name in all uppercase, with _API
stuck on the end. It is basically there to tell Unreal’s build tools that “this particular class needs to be exposed for things to use and subclass”.
So, as an example, my game mode for Rooitactics-based games – which needs to be exposed outside of the module – is declared with:
UCLASS(Blueprintable, Category = "Tactics Engine")
class ROOITACTICSRUNTIME_API ATacticalGameMode : public AGameModeBase
{
But there are some classes that only exist within Rooitactics and don’t need to be subclassed or referenced in blueprints or anything; those don’t have the ROOITACTICSRUNTIME_API
tacked into their class definition. Moreover, I don’t need anything in RooitacticsEditor to be exposed in that manner; everything it does is just registering new commands/functionality with the level editor tool (and some new details panel customizations). So while Unreal also creates a ROOITACTICSEDITOR_API
for that module, I simply don’t use it anywhere.
If you don’t make a plugin and just make a module directly under your project (which is very useful for separating out functionality without all the fuss of a plugin) it will still define those bits for you. In fact, if you look through Unreal itself, you’ll find that modules within the engine are using the <MODULENAME>_API
defines themselves.
Hopefully that helps a bit?