Plugins, How To Use CPP Code Of Plugin In Your Project
Overview Author: () Dear Community, When you have a UE4 code plugin whose code you want to utilize in your main UE4 project, here are the steps you need to take to be able to directly refer to and ...
Overview
Author: ()
Dear Community,
When you have a UE4 code plugin whose code you want to utilize in your main UE4 project, here are the steps you need to take to be able to directly refer to and subclass C++ Code from the plugin!
Step 1: Plugin must export the proper classes
The first step is required of the plugin writer, you must properly export the classes you want other people to be able to use, here is example from my RamaSaveSystem Plugin:
#pragma once
#include "RamaSaveComponent.h"
#include "RamaSaveEngine.h"
#include "RamaSaveLibrary.generated.h"
UCLASS()
class RAMASAVESYSTEM_API URamaSaveLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
static ARamaSaveEngine* GetOrCreateRamaEngine(UWorld* World);
The part I am trying to emphasize is this:
class RAMASAVESYSTEM_API URamaSaveLibrary
By using the macro RAMASAVESYSTEM_API, UE4 generates all the code for properly exporting this class as a class that other projects can "see into", call functions from, and even inherit from as a subclass! (do a search for "__declspec(dllexport)" for more info).
UE4 generates the macro automatically, so for your plugin it would be YOURPLUGIN_API and you dont have to declare that anywhere. (Correction: A Plugin is a collection of Modules. The Auto-Generated export is for YOURMODULE_API. Which is declared within your plugin.)
Because plugins are .dlls, you can export functionality from that dll for others to call into via the macro that UE4 generates for you automatically.
In the same way you can inherit from AActor in a precompiled UE4 engine version (without compiling a custom engine), so you can enable people to inherit from your plugin classes by properly exporting them as shown above.
Step 2: Build.cs
The user of the plugin's code has to include the plugin in their build cs, so your build cs will end up looking something like this:
PublicDependencyModuleNames.AddRange(new string[] {
"Core",
"CoreUObject",
"Engine",
"InputCore",
"UMG", "Slate", "SlateCore",
"AIModule",
"PhysX", "APEX",
//Rama Plugins
"RamaSaveSystem" //