Pawn Destionation always 0.0,0.0,0.0

Any idea what I’m probably missing this? The bot rotates Ok towards player but destination is always 0.0,0.0,0.0.

AIController.cpp


// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.

#include "Nex.h"
#include "NexAIController.h"


ANexAIController::ANexAIController(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	BlackboardComp = PCIP.CreateDefaultSubobject<UBlackboardComponent>(this, TEXT("BlackBoardComp"));

	BehaviorComp = PCIP.CreateDefaultSubobject<UBehaviorTreeComponent>(this, TEXT("BehaviorComp"));

	bWantsPlayerState = true;
}

void ANexAIController::Possess(APawn* InPawn)
{
	Super::Possess(InPawn);

	ANexBot* Bot = Cast<ANexBot>(InPawn);

	// start behavior
	if (Bot && Bot->BotBehavior)
	{
		BlackboardComp->InitializeBlackboard(Bot->BotBehavior->BlackboardAsset);

		EnemyKeyID = BlackboardComp->GetKeyID("Enemy");
		NeedAmmoKeyID = BlackboardComp->GetKeyID("NeedAmmo");

		BehaviorComp->StartTree(Bot->BotBehavior);
	}
}

void ANexAIController::BeginInactiveState()
{
	Super::BeginInactiveState();

	AGameState* GameState = GetWorld()->GameState;

	const float MinRespawnDelay = (GameState && GameState->GameModeClass) ? GetDefault<AGameMode>(GameState->GameModeClass)->MinRespawnDelay : 1.0f;

	GetWorldTimerManager().SetTimer(this, &ANexAIController::Respawn, MinRespawnDelay);
}

void ANexAIController::Respawn()
{
	GetWorld()->GetAuthGameMode()->RestartPlayer(this);
}

void ANexAIController::FindClosestEnemy()
{
	APawn* MyBot = GetPawn();
	if (MyBot == NULL)
	{
		return;
	}

	const FVector MyLoc = MyBot->GetActorLocation();
	float BestDistSq = MAX_FLT;
	ANexCharacter* BestPawn = NULL;

	for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; ++It)
	{
		ANexCharacter* TestPawn = Cast<ANexCharacter>(*It);
		if (TestPawn && TestPawn->IsEnemyFor(this))
		{
			const float DistSq = (TestPawn->GetActorLocation() - MyLoc).SizeSquared();
			if (DistSq < BestDistSq)
			{
				BestDistSq = DistSq;
				BestPawn = TestPawn;
			}
		}
	}

	if (BestPawn)
	{
		SetEnemy(BestPawn);
	}
}

void ANexAIController::SetEnemy(class APawn* InPawn)
{
	if (BlackboardComp)
	{
		BlackboardComp->SetValueAsObject(EnemyKeyID, InPawn);
		SetFocus(InPawn);
	}
}

class ANexCharacter* ANexAIController::GetEnemy() const
{
	if (BlackboardComp)
	{
		return Cast<ANexCharacter>(BlackboardComp->GetValueAsObject(EnemyKeyID));
	}

	return NULL;
}

void ANexAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn)
{
	// Look toward focus
	FVector FocalPoint = GetFocalPoint();
	if (!FocalPoint.IsZero() && GetPawn())
	{
		FVector Direction = FocalPoint - GetPawn()->GetActorLocation();
		FRotator NewControlRotation = Direction.Rotation();

		NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw);

		SetControlRotation(NewControlRotation);

		APawn* const P = GetPawn();
		if (P && bUpdatePawn)
		{
			P->FaceRotation(NewControlRotation, DeltaTime);
		}

	}
}

Where are you setting your blackboard value? I’m not finding any code along the lines of “BlackboardComp->SetBlackboardValueAsVector(Destination_ID, value)”

I can’t find that kind of code in ShooterGame either. I’m trying to build that piece by piece.

I believe ShooterGame uses blueprints to set their blackboard…see below for how to set blackboard keys through c++.

I’ll have a look. Thanks!

Apparently the blueprint for some reason does not set the destination so I decided to test what you said. I did something like this in AIController’s FindClosestEnemy method.


BlackboardComp->SetValueAsVector(DestinationID, TestPawn->GetActorLocation());

Of course I had to setup the DestinationID in AIController’s Possess method:


DestinationID = BlackboardComp->GetKeyID("Destination");

Also for someone who is following this. Remember add DestinationID variable in AIController header.