Download

How to expose pawn/actor pointer to blueprints ?

Hi guys,
i’m having an issue with referencing an actor to blueprints, maybe someone can help me out here…

The following code iterates through all players online. I need the pointer from the last pawn exposed when calling the function from a blueprint…



void UGenericHelper::CheckAllPlayersIfInRange(float requiredDistance, bool &bHasPlayerInRange, float &closestPlayer, APawn *refPawn)
{
	for (auto ControllerIt = GetWorld()->GetPlayerControllerIterator(); ControllerIt; ++ControllerIt)
	{
		APlayerController *Controller = *ControllerIt;
		const auto pawn = Controller->GetPawn();
		bHasPlayerInRange = false;

		if(pawn)
		{
			refPawn = pawn;


However, refPawn shows up as an input node. I thought it is not a big deal, so i just created a pawn ref and plugged it into the node but it is always null/invalid.

Hi Burnz,
you’ll need to pass the pawn parameter into the function as a reference pointer.


UFUNCTION(BlueprintCallable)
void CheckAllPlayersIfInRange(float requiredDistance, bool& bHasPlayerInRange, float& closestPlayer, **APawn*&** refPawn)


Then it will show up as an output pin and store the value written inside the function.

Hello Alderbit!
thanks for the swift reply - works perfectly. Are you available for engine tutoring or consulting ? While i code in C++ for 15 years now i’d could use some help with some engine work. If so please send me a PM!

Ah never mind, brain fart.