How to call a blueprint function from c++

hey guys,

first of all: sorry for my bad English and I’m new to Unreal Engine.

I’ve got a Blueprint project mixed with some c++ code / files. Now what I want to do, is to simply call a Blueprint function from within c++ code. It does sound simple and I think I’m doing an obvious mistake, but I just cant find it, although I searched a lot for an solution.
I have a APlayerControllerP.cpp file, which is also set as default player controller in my project and a HUDbp blueprint, which is set as default HUD. Within the HUDbp, there is a function called “debugFunction”, which I would like to call.
I’ve tried things like

AHUD* myHUD = this->GetHUD();
myHUD->debugFunction();

or

	static ConstructorHelpers::FObjectFinder<UBlueprint> myHUD(TEXT("Blueprint'/Game/HUDbp.HUDbp'"));
	{
		if (myHUD.Object != NULL)
		{
			myUhud.Object->debugFunction();
		}
	}

both within the constructor of APlayerControllerP.cpp.

the referencing works, but I guess its the wrong reference, because it just can’t find the function…

please help me :slight_smile:

Blueprint is running on virtual machine, so everything you do in blueprint does not exist in compile time so C++ code can’t directly reference it and call it, blueprints can be only accessed on runtime when everything is loaded.

My recommended method for this is to create C++ base class for your blueprint which will allow you to refrence blueprint stracture inside C++ side. In such base class create C++ function with BlueprintNativeEvent BlueprintImplementableEvent (1st option let you implement function in C++ as if you use those specifiers it will block ability to define those functions in c++), then zou simply override in blueprint based of that C++ class and when you call it in C++ it will call event in blueprint. More complex way is to get blueprint function identifier and call it using it, i explain that here

There is feature in UE4 that is coming which will compile blueprint in to C++ code, i suspect with that zou will be able to refrence blueprint code in C++ a lot easier when this got implemented

oh wow, I really didn’t know that. Thanks a lot for your help and your explanation!

I’ve created now a blueprint, based on my c++ class as you suggested.
I also implemented a BlueprintImplementableEvent inside the header of my c++ class and it even shows up within my blueprint class.

	UFUNCTION(BlueprintImplementableEvent, Category = "updating HUD")
		void updateHUDblueprint();

In my c++ class I’m just calling updateHUDblueprint() as if it was a normal function.
The problem is, that it just doesn’t trigger, and I don’t know why.
The blueprint is spawned by the “Event BeginPlay” of my standard HUD blueprint, might that be the mistake?