How to convert Existing C++ Class to a plugin

I have couple of Actor Component C++ Class that i need it to be converted to a plugin to be used on other projects
How do i do it. ??


The short form is:

  1. Go to Edit > Plugins
  2. Click the “Add” button and enter information for your new plugin, whatever it might be.
  3. Copy the header files for your actor components into Plugins\<whatever>\Source\Public
  4. Copy the cpp files for your actor components into Plugins\<whatever>\Source\Private
  5. Make sure any other modules your plugin uses are declared in <whatever>.Build.cs in the Plugins\<whatever> directory.
  6. Make sure the classes you want exported have the appropriate <WHATEVER>_API prefix on the class definitions, like for a hypothetical “CoolActorPlugin” you’d have:
    class COOLACTORPLUGIN_API UCoolComponent : public UCharacterComponent
  7. Now if you want to use it in another project, you just drop that directory into a new project’s Plugins directory and you’ve got your components there.

(I suppose that wasn’t really the “short” form, per se, but.)

1 Like

How does point 6 Works.
Lets say my Game Name is FPSgame and plugin name isFPSgameplugin
so my current class prefix is FPSgame_API so i Changed to FPSgameplugin_API (all caps)
Getting a lots of errors and unable to complie

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.


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?


Hello. I am Trying to do the same for all the classes of the lyra Project. I want to migrate all the classes inside my game feature so I can load my plugin in any project. Altough, the folder structure if different and I wasn’t able to do it. Any ideas?