Sharing Code between BTServices

So during this lesson of BTServices, it was mentioned that BTService_PlayerLocation and BTService_PlayerLocationIfSeen was duplicating some identical code (namely the code that sets the Selected Blackboard Key to the PlayersLocation), and that it is possible for that to be minimised by calling this functionality instead from one location.

APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
if (!PlayerPawn) { return; }
OwnerComp.GetBlackboardComponent()->SetValueAsVector
(
GetSelectedBlackboardKey(),
PlayerPawn->GetActorLocation()
);

Now obviously in this example, there’s only two instances of the code, so setting it up for them to share is not worth the effort, but if this was a bigger project, with several BTServices using this code, I was wondering what would be the best way to set it up so all the different BTServices could share the code?

Privacy & Terms