I have the following function:
void AAI_BookController::BookPatrol()
{
APawn* MyBot = GetPawn();
if (MyBot == NULL)
{
return;
}
AAI_BasicEnemy* BaseEnemy = (AAI_BasicEnemy*)GetPawn();
BaseEnemy->StartWalk();
FVector MyLoc = MyBot->GetActorLocation();
float AddX;
float AddY;
float NewWhereShouldAIPatrolTo; //Voor de Blackboard key: WhereShouldAIPatrolTo
//Check de huidige waarde van WhereShouldAIPatrolTo
if (WhereShouldAIPatrolTo == 5)
{
AddX = 100;
AddY = 100;
NewWhereShouldAIPatrolTo = 6;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("kom ik hier! if1"));
}
else if (WhereShouldAIPatrolTo == 6)
{
AddX = 100;
AddY = -100;
NewWhereShouldAIPatrolTo = 7;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("kom ik hier! if2"));
}
else if (WhereShouldAIPatrolTo == 7)
{
AddX = -100;
AddY = -100;
NewWhereShouldAIPatrolTo = 8;
}
else if (WhereShouldAIPatrolTo == 8)
{
AddX = -100;
AddY = 100;
NewWhereShouldAIPatrolTo = 9;
}
//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::FromInt(NewWhereShouldAIPatrolTo));
//Pas de WhereShouldAIPatrolTo nummer aan zodat die een andere kant op loopt volgende keer
BlackboardComp->SetValueAsFloat(WhereShouldAIPatrolTo, NewWhereShouldAIPatrolTo);
//Pas de locatie waar de AI moet heen lopen aan en stuur deze naar het Blackboard
float NewX = MyLoc[0] + AddX;
float NewY = MyLoc[1] + AddY;
MyLoc.Set(NewX, NewY, MyLoc[2]);
BlackboardComp->SetValueAsVector(SetPatrolRoute, MyLoc);
}
This function is being called by the Behavior tree every tick so that my AI will (if it all works the way I think it should) move in circles. Now the problem is that my WhereShouldAIPatrolTo is not being changes even when I use:
BlackboardComp->SetValueAsFloat(WhereShouldAIPatrolTo, NewWhereShouldAIPatrolTo);
Does someone know what is happening ? cause when I use breakpoints on the code above my NewWhereShouldAIPatrolTo is 6, but when the function is being called again its 5 again…