Calling a function from another class

I have a function in my EnemyCharacter cpp file called GetIsFrozen and I am trying to call it in my FindPlayer cpp file.

  // Fill out your copyright notice in the Description page of Project Settings.
    
    #include "BTService_FindPlayer.h"
    #include "EnemyAIController.h"
    #include "EnemyCharacter.h"
    #include "BehaviorTree/Blackboard/BlackboardKeyType_Object.h"
    
    UBTService_FindPlayer::UBTService_FindPlayer()
    {
    	bCreateNodeInstance = true;
    }
    void UBTService_FindPlayer::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
    {
    	Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
    	auto EnemyAIController = Cast<AEnemyAIController>(OwnerComp.GetAIOwner());
    
    	AEnemyCharacter* FrozenChar = Cast<AEnemyCharacter>(WHAT GOES IN HERE?);
    	
    
    	if (EnemyAIController && FrozenChar)
    	{
    		auto PlayerPawn = GetWorld()->GetFirstPlayerController()->GetPawn();
    		OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Object>(EnemyAIController->TargetKeyID, PlayerPawn);
    		UE_LOG(LogTemp, Warning, TEXT("Target has been set!"));
    	}
    
    
    }

To call a function in your EnemyCharacter.cpp, you need a pointer to that object and the function you want to call GetIsFrozen() needs to be declared “public” in EnemyCharacter.h.

I’m assuming by the filename that EnemyCharacter is of class Character and is the same entity as PlayerPawn (ACharacter is a subclass of APawn) you get with the call:

auto PlayerPawn = GetWorld()->GetFirstPlayerController()->GetPawn();

Im also assuming that GetIsFrozen() returns a bool indicating whether the character is frozen or not.

So I think if you moved your PlayerPawn declaration/initialization line before your AEnemyCharacter* line then your EnemyCharacter line can be like the second line below:

auto PlayerPawn = GetWorld()->GetFirstPlayerController()->GetPawn();
AEnemyCharacter* FrozenChar = Cast<AEnemyCharacter>(PlayerPawn);

(By the way, I would have thought you would have APawn* PlayerPawn… rather than using auto but maybe there is something you are doing that I cannot see and therefore don’t understand).

The remaining TODOs are to call the function to obtain the bool result and use that in an IF statement (assuming you only want the blackboard targeting to occur if IsFrozen is true):

if (EnemyAIController && FrozenChar)
         {
             if(FrozenChar->GetIsFrozen())
                {
                     OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Object>(EnemyAIController->TargetKeyID, PlayerPawn);
                      UE_LOG(LogTemp, Warning, TEXT("Target has been set!"));
                 }
         }

Hopefully I’ve made the right assumptions and this is helpful. I’m pretty sure this works but haven’t tested the code myself.