Error C2664: Cannot convert argument 1 from 'const TWeakObjectPtr'

Hello everyone, I am a beginner in c ++ in eu4 and I am reading the book ‘Mastering Unreal Engine 4’ and I found a problem. When I write the AI ​​code, at the time of compiling these errors appear: *EnemyAIController.cpp(104): error C2664: ‘bool AEnemyAIController::PawnCanBeSeen(APawn *)’: Cannot convert argument 1 from ‘const TWeakObjectPtr’ to 'APawn and EnemyAIController.cpp (43): error C2664: ‘void UBlackboardComponent :: SetValueAsVector (const FName &, FVector)’: Cannot convert argument 1 from ‘int32’ to ‘const FName &’. Does anyone there know how to fix these errors? If you know please reply to this message. Thank you!
CPP:

//This is the CPP
#include "EnemyAIController.h"
#include "Enemy.h"
#include "Bellz.h"
#include "BehaviorTree/BehaviorTree.h"
#include "BehaviorTree/BehaviorTreeComponent.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "BehaviorTree/Blackboard/BlackboardKeyType_Object.h"


AEnemyAIController::AEnemyAIController() {

	BlackboardComp = CreateDefaultSubobject<UBlackboardComponent>(TEXT("Blackboard"));
	BehaviorTreeComp = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("BehaviorTree"));
	bWantsPlayerState = true;
}

void AEnemyAIController::Possess(APawn * InPawn)
{

	AEnemy* _tempEnemy = Cast<AEnemy>(InPawn);

	if (_tempEnemy && _tempEnemy->EnemyBehaviorTree) {

		BlackboardComp->InitializeBlackboard(*_tempEnemy->EnemyBehaviorTree->BlackboardAsset);
		EnemyKeyID = BlackboardComp->GetKeyID("Enemy");
		EnemyPositionKeyID = BlackboardComp->GetKeyID("EnemyPosition");
		BehaviorTreeComp->StartTree(*_tempEnemy->EnemyBehaviorTree);
	}

}

void AEnemyAIController::BeginInactiveState()
{
}

void AEnemyAIController::SetEnemy(class APawn * InPawn)
{
	if (BlackboardComp) {

		BlackboardComp->SetValue<UBlackboardKeyType_Object>(EnemyKeyID, InPawn);
		BlackboardComp->SetValueAsVector(EnemyPositionKeyID, InPawn->GetActorLocation());
		SetFocus(InPawn);

	}

}

AGladiatorReview * AEnemyAIController::GetEnemy() const
{
	if (BlackboardComp) {

		return Cast<AGladiatorReview>(BlackboardComp->GetValue<UBlackboardKeyType_Object>(EnemyKeyID));


}
	return NULL;
}

void AEnemyAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn)
{


	 FVector TheCenter = GetFocalPoint();
	if (!TheCenter.IsZero() && GetPawn()) {

		FVector Direction = TheCenter - GetPawn()->GetActorLocation();
		FRotator TheNewRotation = Direction.Rotation();
		TheNewRotation.Yaw = FRotator::ClampAxis(TheNewRotation.Yaw);
		SetControlRotation(TheNewRotation);

		APawn* const  _tempPawn = GetPawn();
		if (_tempPawn && bUpdatePawn) {

			_tempPawn->FaceRotation(TheNewRotation, DeltaTime);

		}

	}
}

bool AEnemyAIController::PawnCanBeSeen( APawn * target)
{
	return false;
}

void AEnemyAIController::OnSearchEnemy()
{
	APawn* _tempPawn = GetPawn();

	if (_tempPawn == NULL) {
		return;
	}
	const FVector _tempLocation = _tempPawn->GetActorLocation();
	float BestDiskSQ = MAX_FLT;
	AGladiatorReview* PlayerPawn = NULL;

	for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; ++It) {


		
			AGladiatorReview* TestPawn = Cast<AGladiatorReview>(*It);
			if (PawnCanBeSeen(*It)) {

			AEnemy* const _testEnemy = Cast<AEnemy>(TestPawn);
			if (_testEnemy) {

			}
			else {


			
				if (TestPawn && TestPawn->GetIsStillAlive()) {
					const float _distanceSq = (TestPawn->GetActorLocation() - _tempLocation).SizeSquared();
					if (_distanceSq < BestDiskSQ) {

						BestDiskSQ = _distanceSq;
						PlayerPawn = TestPawn;

					}

				}
			}

		}
		if (PlayerPawn) {

			SetEnemy(PlayerPawn);

		}
	}
}

/*if (BlackboardComp) {

		BlackboardComp->SetValue<UBlackboardKeyType_Object>(EnemyKeyID, InPawn);
		BlackboardComp->SetValueAsVector(EnemyPositionKeyID, InPawn->GetActorLocation());
		SetFocus(InPawn);





	}*/

Header File:

#pragma once

#include "CoreMinimal.h"
#include "AIController.h"
#include "BehaviorTree/BehaviorTreeComponent.h"
#include "GladiatorReview.h"
#include "EnemyAIController.generated.h"

/**
 * 
 */
UCLASS()
class BELLZ_API AEnemyAIController : public AAIController
{
	GENERATED_BODY()
public:

	
	AEnemyAIController();
	
	UPROPERTY(transient)
		UBlackboardComponent* BlackboardComp;


	UPROPERTY(transient)
		UBehaviorTreeComponent* BehaviorTreeComp;

	virtual void Possess(class APawn* InPawn) override;


	virtual void BeginInactiveState() override;


	UFUNCTION(BlueprintCallable, Category = "Behavior")
		void SetEnemy(class APawn* InPawn);


	UFUNCTION(BlueprintCallable, Category = "Behavior")
		class AGladiatorReview* GetEnemy() const;


	UFUNCTION(BlueprintCallable, Category = "Behavior")
		void UpdateControlRotation(float DeltaTime, bool bUpdatePawn);

	UFUNCTION(BlueprintCallable, Category = "Behavior")
		bool PawnCanBeSeen(APawn* target);

	UFUNCTION(BlueprintCallable, Category = "Behavior")
		void OnSearchEnemy();

protected:
	int32 EnemyKeyID;
	int32 EnemyPositionKeyID;


};

Compiler Result:

Hmmm I can’t repro the error. Although on a side note, you should not have #include “GladiatorReview.h” in your .h file. the ‘class AGladiatorReview* GetEnemy() const;’ is a forward decoration of the class. This is done to prevent circle includes. can you post the header for the gladiatorreview class?

It seems to me the problem is you are calling up your PawnCanBeSeen function using a FConstPawnIterator which contains (as the name implies) a constant object pointer. However, your function, as it is currently declared, requires it be fed a non-constant object pointer, which means the compiler assumes that the function is allowed to modify the pointed-to object (even if it doesn’t actually do so).

This means your function isn’t allowed to be fed a constant object pointer, like those contained by the FConstPawnIterator, because constant objects can’t be modified, but the compiler assumes your function does modify this parameter (in this case, the pointed-to object).

So try changing your PawnCanBeSeen function declaration to make its parameter constant, like so:

UFUNCTION(BlueprintCallable, Category = "Behavior")
bool PawnCanBeSeen(const APawn* target);

Since you aren’t modifying the pointed-to object within this function anyway, it should be fine to make this change. (Actually, I would dare to say this reflects good coding practice.) This will tell the compiler that your function does not modify the pointed-to target object in any way, and allow the function to work the way you need it to.

Or at least I think.

Hopefully that does it and everything compiles fine after.