1. Home
  2. Docs
  3. Unreal Engine 4
  4. Programming
  5. Create an engine plugin using Blank Plugin

Create an engine plugin using Blank Plugin

Prerequisites :

The development of a new plugin, using the “4.16/engine” Directory isn’t the best way to go at start,if i can’t to compile well, other project stored into the launcher library that use this engine version will no longer start, because of the compile errors.

The best practice is to create a new project, to configure the plugin and make bring it to compile code successfully, before to move it onto the engine directory of your version of Unreal Engine.

  • Create a new c++ blank project from the project browser. ( note -–> it will built the solution and launch in UE4.)

It’s necessary to have generated a solution file for your project before you can compile a plugin for your project.

  • go at the root of your project.
  • Do a right click on the *.Uproject file then Generate Visual Studio project file.

2015-10-30_18-22-35

 

 

  • Now we need to create a plugins directory into “project_name\Plugins“.
  • Copy the blankplugin from “4.9\Engine\Plugins\Developer” to “project_name\Plugins\Developer\MyPlugin
  • Rename”blankplugin.uplugin” to “myPlugin.uplugin
  • Open the file in notepad and then edit like below.

{
	"FileVersion" : 3,
	
	"FriendlyName" : "Blank Example Plugin Test",
	"Version" : 1,
	"VersionName" : "1.0",
	"CreatedBy" : "fuzz",
	"CreatedByURL" : "http://epicgames.com",
	"EngineVersion" : "4.9.0",
	"Description" : "Just a test.",
	"Category" : "Examples",
	
	"Modules" :
	[
		{
			"Name" : "MyPlugin",
			"Type" : "Developer"
		}
	]
}
  • Go back at the root of your project, and then Delete the Binaries and Intermediate directories.

Files Renaming

Open the “MyProject/Source” directory , and rename all the .cpp, .h and .cs files like listed below :

Engine\Plugins\Developer\BlankPlugin\BlankPlugin.uplugin >> Plugins/Developer/MyPlugin/MyPlugin.uplugin
Engine\Plugins\Developer\BlankPlugin\Source\BlankPlugin\BlankPlugin.Build.cs >> Plugins/Developer/MyPlugin/MyPlugin.Build.cs
Engine\Plugins\Developer\BlankPlugin\Source\BlankPlugin\PrivateBlankPlugin.cpp >> Plugins/Developer/MyPlugin/Private/MyPlugin.cpp
Engine\Plugins\Developer\BlankPlugin\Source\BlankPlugin\PrivateBlankPluginPrivatePCH.h >> Plugins/Developer/MyPlugin/Private/MyPluginPrivatePCH.h
Engine\Plugins\Developer\BlankPlugin\Source\BlankPlugin\Public IBlankPlugin.h >> Plugins/Developer/MyPlugin/Public/IMyPlugin.h

Open them all with a text editor (notepad or notepad++) and then just remove all the references to “BlankPlugin”

Example : I had renamed “MyPlugin” for the purpose of this mini tutorial.

File : “Plugins/Source/MyPlugin/MyPlugin.Build.cs”

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

namespace UnrealBuildTool.Rules
{
	public class MyPlugin : ModuleRules
	{
		public MyPlugin(ReadOnlyTargetRules Target) : base(Target)
		{
			PublicIncludePaths.AddRange(
				new string[] {
					// ... add public include paths required here ...
					"MyPlugin/Public"
				}
				);

			PrivateIncludePaths.AddRange(
				new string[] {
					"MyPlugin/Private",
					// ... add other private include paths required here ...
				}
				);

			PublicDependencyModuleNames.AddRange(
				new string[]
				{
					"Core",
					// ... add other public dependencies that you statically link with here ...
				}
				);

			PrivateDependencyModuleNames.AddRange(
				new string[]
				{
					// ... add private dependencies that you statically link with here ...
				}
				);

			DynamicallyLoadedModuleNames.AddRange(
				new string[]
				{
					// ... add any modules that your module loads dynamically here ...
				}
				);
		}
	}
}

File : Plugins/Source/MyPlugin/Private/MyPluginPrivatePCH.h

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#include "IMyPlugin.h"

// You should place include statements to your module's private header files here.  You only need to
// add includes for headers that are used in most of your module's source files though.

File : Plugins/Source/MyPlugin/Private/MyPlugin.cpp”


// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
// Private/MyPlugin.cpp

#include "MyPluginPrivatePCH.h"

class FMyPlugin : public IMyPlugin
{
	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;
};

IMPLEMENT_MODULE( FMyPlugin, MyPlugin )

void FMyPlugin::StartupModule()
{
	// This code will execute after your module is loaded into memory (but after global variables are initialized, of course.)
}

void FMyPlugin::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.
}

File : Plugins/Source/MyPlugin/Public/IMyPlugin.h

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "ModuleManager.h"


/**
 * The public interface to this module.  In most cases, this interface is only public to sibling modules 
 * within this plugin.
 */
class IMyPlugin : public IModuleInterface
{

public:

	/**
	 * Singleton-like access to this module's interface.  This is just for convenience!
	 * Beware of calling this during the shutdown phase, though.  Your module might have been unloaded already.
	 *
	 * @return Returns singleton instance, loading the module on demand if needed
	 */
	static inline IMyPlugin& Get()
	{
		return FModuleManager::LoadModuleChecked< IMyPlugin >( "MyPlugin" );
	}

	/**
	 * Checks to see if this module is loaded and ready.  It is only valid to call Get() if IsAvailable() returns true.
	 *
	 * @return True if the module is loaded and ready to use
	 */
	static inline bool IsAvailable()
	{
		return FModuleManager::Get().IsModuleLoaded( "MyPlugin" );
	}
};

When it’s done, go at the root of your project, then

  1. delete the sln, suo files
  2. right click and generate solution file.

Recompile the project

You can create a batch file at the root of the project, so you can rebuild the plugin just by executing the batch instead of running Visual Studio.

(just edit the path accordingly to your drive and paths)

Copy that into a new txt file, and rename to build_plugin.bat

"C:/Epic Games/4.9/Engine/Binaries/DotNET/UnrealBuildTool.exe" MyProject Development Win64 -project="C:/Ue4_Projects/MyProject/MyProject.uproject" -rocket -editorrecompile -progress
pause

Deploy the plugin as Engine Plugin

The plugin should compile fine, but it’s a game plugin, because the plugin is hosted into the Game Project.

If you want to share the plugin at the engine level,

  1. You just need to copy the directory “MyProject/Plugins/developer/MyPlugin/” to “4.9\Engine\Plugins\Developer/MyPlugin/ “.
  2. Delete the Binaries and Intermediates directory,
  3. Launch UE4, it should recompile the plugin before the editor loads
  4. If everything is proper, now the plugin should be displayed into the plugin manager into the “built -in > examples” section.

 

Nicolas Kirsch

Updated : 06 Nov 2015

Was this article helpful to you? Yes No

How can we help?