Call blueprint event from plugin code

Hi, I’ve been trying to look how to do this but i couldn’t find a clear answer. What I want to do is to activate a blueprint custom event from the plugin code ( in my case from recieving custom device input, Kinect v2). How do I do this? Where? Sorry if this is a noobish question, I just started with Unreal Engine and C++.
To specify more, I need to do a plugin that recieves custom Kinect v2 inputs from a library (.dll) I already have, and then upon recieving certain input, it activates an event inside the game. This is for the game to accept any kind of input later on, not only the Kinect v2 inputs. For example, when the user lowers his hand, it will fire an event called selectMenuDown that selects the next option in the menu under the selected one.

This is for my end-of-degree project. Thank you.

Blueprints are just dynamically created C++ classes under the hood, so normally calling a blueprint event is as simple as myObject.myEvent(); assuming you set myEvent to a BlueprintImplementableEventin your header file.

Probably the easiest way for you to learn how to do this is to simply find an event or method that already exists in the engine and just read the source code to figure how its setup and then mirror that process. Being a plugin or what not shouldn’t matter in this case.


You can take a look at the ufunction specifier BlueprintNativeEvent. It is a virtual function declared in C++ which allows you to provide a native C++ implementation and be overriden by blueprints in the form of events. Here let me give you a small sample code:

// Inside a uclass body; let's call the class UFoo:
UFUNCTION(BlueprintNativeEvent, Category = "MandatoryCategory")
void OnEvent();

// in .cpp file
void UFoo::OnEvent_Implementation()

Taking a closer look you will see that in the .cpp file the function name is suffixed with ‘_Implementation’. This is done with all native events. What happens is the Unreal Header Tool (UHT) generates a declaration for that suffixed function(OnEvent_Implementation) and an implementation for the actual function (OnEvent); the generated implementation will call the blueprint version of the event if one exists and otherwise it will call OnEvent_Implementation.

Left to do for you is creating a blueprint that inherits from UFoo and calling the event in C++; for this purpose call OnEvent and not OnEvent_Implementation.


Thank you for your replys, they were very useful. I achieved making a c++ class that calls blueprintImplementable events when recieving inputs (in c++) But now I want to move that to a plugin and I find the following problems:

1 - The macro UFUNCTION() is not recognized. Do I have to include anything for this to work?

2 - In the c++ class I used SetupPlayerInputComponent(class UInputComponent* InputComponent) to bind inside the function keyboard keys( As an example of input), but when I write this in the .h input file it says “Function definition for “SetupPlayerInputComponent” not found.”

3 - In the InputPlugin.cpp file, there is :

IMPLEMENT_MODULE(FInputPluginModule, InputPlugin)

at the end of the code. Can I write code under it? What is it for?

This is my InputPlugin.h code:

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

#pragma once

#include "ModuleManager.h"
//#include "IInputDeviceModule.h"

class FInputPluginModule : public IModuleInterface

	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;
	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
	void Right();
	UFUNCTION(BlueprintImplementableEvent, Category = "Input")
		void Right_BP();
	void Left();
	UFUNCTION(BlueprintImplementableEvent, Category = "Input")
		void Left_BP();
	void Accept();
	UFUNCTION(BlueprintImplementableEvent, Category = "Input")
		void Accept_BP();

  1. You probably are missing the includes:

#include "UObject/ObjectMacros.h"
#include "UObject/ScriptMacros.h"

You might just need the ScriptMacros.h, but I honestly don’t remember and can’t check right now.

  1. SetupPlayerInputComponent is not a valid method contained by IModuleInterface, so you’re trying to overload a base class method that doesn’t exist. Remove the override keyword.

  2. IMPLEMENT_MODULE is just a macro that implements some required boiler plate code for any module. Technically there’s no reason why you can’t put code under it, but honestly you may want to look at some of the other plugins (Paper2D is a great resource) for a better idea on how to structure your plugin.

EDIT: Also, I’m not sure you can have UFUNCTIONS on a non-UObject (IModuleInterface is not a UObject). You probably want to move that code to some other object (Make a class named UInputPlugin or some such that contains all your methods).