How to turn an existing C++ class into a plugin?


I’ve done a horrible mistake of writing a C++ plugin for UE4 before knowing how UE4 plugins actually work. I assumed I will first simply write it as a regular project C++ class and turn it into a plugin afterwards. I’ve spent last 3 months writing the plugin, and it’s now almost done, but it appears that the act of turning it into a plugin is a more challenging project than the plugin itself. I’ve just started to read how C++ plugins for UE4 are made and I have absolutely no clue how to pull it off.

There seems to be some vague poor documentation on how to create a blank plugin, but absolutely no info how to transfer already existing C++ class into a plugin form. After googling around and finding many obscure threads, I am in fact even more confused and even more clueless then I was when I began researching it. People are suggesting really confusing workarounds of shuffling the files around, renaming then, copypasting their contents, etc…

There seems to be some overcomplicated concept of modules I probably don’t even need for my simple plugin which is just one actor class and one component class, yet I really have no idea how to get over that either. :frowning:

There must be some right way to do it… or?

Unreal plugins are modules.
Unfortunately over 90% of everything that should be known before developing a plugin, Epic never wrote any documentation about it… So yeah, very poor docs, they assume you know U’C++ and can figure by yourself when making one.

Yes, I was very surprised how much more I need to know about internal workings of the engine before I can do even simplest of the C++ plugins, compared to just project C++ classes. Anyway, I made some progress:

I deleted .vs, .sln and binaries folder. Then I moved my classes into the source folder that got generated inside the folder generated by New Plugin wizard. After that I made sure I include the same modules I needed in my game build.cs in my plugin’s build.cs. After that, I regenerated the VS files, but it still did not compile. But after I deleted the PROJECTNAME_API macro in front of the class name, it compiled and so far it works! The problem is that:
A: I have no idea what the implications of deleting that macro are.
B: I do not know what was that macro supposed to do.

So I am now in the state where it works, but I have no idea why. And to know why, I will probably have to dig deep into the intricacies of all the UE4’s C++ boilerplate macros :expressionless:

That macro basically means “export this class so all modules using this module can see it and use it”.

If you want games to use a class from your plugin you have to export it, using PLUGINMODULENAME_API macro to export it;
Otherwise other modules and game code can’t use it, only your own plugin can use it.

This is why you add things inside a Build.cs file of a project, when you add to Build.cs a module name (like a plugin’s module name), then everything exported by that _API macro can now be used because Build.cs will import that class definitions for you before building the game.

Yes, I’ve just got stuck exactly on this. I tried to package the plugin from the plugins window, without much success. I get an error if I send the plugin to a friend. It’s something regarding the modules but I don’t remember exactly what. Anyway. where do I find the name of the plugin module I’ve created? I’ve simply tried to add name of my module all caps without any spaces suffixed by _API in front of the class name, but no luck. So far I have a class in my plugin’s folder source folder without that macro.

This is why I don’t like to use and never used that button to auto generate a plugin.
It creates a lot of code that you should know and should write yourself a few times before having a tool create it for you, it slows down the learning process…

Somewhere in your plugin files there is a *IMPLEMENT_GAME_MODULE *or a *IMPLEMENT_MODULE *macro.
Whatever is in there is what you use all caps before _API.

Hi [USER=“434”]BrUnO XaVIeR[/USER] ,
After creating plugins its sometimes hard to hot reload them, they fails. So we have to manually go to plugin compilation window in UEditor and make a compilation command from there, which is very tidious, can you share some way where when you change the code and hit build in VS, it gets auto updated in the Editor as well

You can override SupportsDynamicReloading() to return true (false by default) in plugin’s module class to make things less clunky; but HotReload doesn’t really support plugins, neither Blueprint nativization…

All you can do is try to avoid getting in their way when someone is using these things, plugins set to load as “PreDefault” can help with that.

I have found sort of an acceptable workaround. If you go to Window>Developer Tools>Modules, it opens a panel where you can individually compile each plugin. I have docked this panel out of the way and filtered it just for my specific plugin. So in the UI, I now have tiny panel with a single compile button and I’ve got used to a habit of clicking that one instead of the toolshelf one:

It’s not great, but it works :slight_smile:

Thanks for the share Rawalanche, I’ve been using this method already, though I felt its more redundant, I will try what Bruno have said and work on it.