featured

In this post, we’re going to create a blank C++ plugin in UE4 and then export it to re-use it on another project. I like to think of plugins as a way to create reusable logic that can be added to other C++ projects fast and easy.

Creating a Plugin

Create a blank C++ project and then, navigate to Edit -> Plugins menu and click the New Plugin button on the bottom right corner. Then, select a blank plugin and name it MyAwesomePlugin just to match the post’s instructions. When Unreal has finished creating your plugin, you have to restart your editor and rebuild your project so your plugin can be included in your project. Once you have completed these steps, open your project inside visual studio and locate the MyAwesomePlugin.uplugin file inside the Plugins folder that has been created by the editor.

vs_uplugin

Click on image to enlarge in a new tab

This file contains all the necessary information about your plugin, while some of these options can be edited through the Editor, I prefer to edit this file instead. Go ahead and perform the marked changes in your file as shown in the screenshot above. We need to mark the plugin as Installed because we would like to export it for later use in another project.

The Type field can take a number of different values, based on what we need:

  • A Runtime value means that our module will exist in the shipping build
  • A Developer value means that your module will be available in the editor and in the development build but not in the shipping build

Once you perform these modifications, build your project and restart the editor.

Then, go ahead and create a new C++ class that inherits the ActorComponent. Please note that while you’re on the c++ wizard you can select where your class resides to. In this case, we’re going to add this component to our plugin:

cpp_class_add

Once you create your class, your compile will fail and the following error will pop up in your output log:

Currently, this is a normal behavior. The workaround for this is to navigate to the MyAwesomePluginPrivatePCH.h file and include the “Engine.h” file right under MyAwesomePlugin.h. Once you complete this step, open up the MyPluginComponent.cpp file and include the MyAwesomePluginPrivatePCH as its header file. To sum up, here are both files at this point:

When you perform these changes, your project will compile just fine. Since the purpose of this post it to understand how to create a basic plugin so we won’t create any fancy behavior for our component, just add a log inside your BeginPlay function:

In this case, let’s assume that the component we have added inside our Plugin is super useful and we want to add it to some actors in our game. To do that, we have to open the [OurProjectName].Build.cs file and include the plugin in the Public Dependency Modules:

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

After completing this step, we can include the MyAwesomeComponent.h header file to an actor class and create the component as any other component. To demonstrate that, I have created a DummyActor and I have added our component:

Packaging our plugin

In order to package your plugin, go to Edit -> Plugins menu and select your plugin. Then, select the Package option. The editor will build your plugin for all the supported platforms and create a folder with your packaged build. To use your plugin in another project, copy the Plugins folder (it is located inside [YourExportFolder]->HostProject) inside your desired project. Please note that the target project has to be a C++ project.

Share postShare on Facebook32Tweet about this on TwitterShare on LinkedIn0Share on Reddit69