Call Blueprint functions from C++

Ok, got this working so here is an example…

I want to call a blueprint function from C++.

So first I make a blueprint function called CallFunctionTest.
(In our game, and we call a player a “Survivor”.)
It just prints “Survivor Call Function Test” in pink on the console.

Then I have a static blueprint set of functions like this…

The header file is

#include "Kismet/BlueprintFunctionLibrary.h"

#include "TDLSurvivorFastCache.generated.h"

/**
 * 
 */
UCLASS()
class TDL_API UTDLSurvivorFastCache : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()


public:

	UFUNCTION(BlueprintCallable, Category = TDLSurvivorCache)
		static void TestCPPCallToBP(AActor * c);
	
};

and the cpp file is…

#include "tdl.h"
#include "ConsoleManager.h"

#include "TDLSurvivorFastCache.h"
   
UTDLSurvivorFastCache::UTDLSurvivorFastCache(const class FObjectInitializer & PCIP)
	: Super(PCIP)
{
	UE_LOG(TDLLog, Log, TEXT("UTDLSurvivorFastCache"));
}

void UTDLSurvivorFastCache::TestCPPCallToBP(AActor * c)
{
	FOutputDeviceNull ar;
	c->CallFunctionByNameWithArguments(TEXT("CallFunctionTest"), ar, NULL, true);
}

Then we call the test function from our SurvivorBP blueprint and it calls the function on the SurvivorBP.


Here are the blueprints

45483-testfunctionimpl.png

45484-calltotestcppfunc.png

4 Likes