Hello all,
So I’m working on a very simple AiController to setup some AI patrolling, and am running into a problem. I have both the subclass and TArray of Actor class declared in the header, mainly so that I can use the out array populated in the 3rd Parameter of the GetAllActorsOfClass method in another method to cycle through it to find the patrol locations. Below is my header and cpp:
Header:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "FPSGuardController.generated.h"
class AFPSAIGuard;
class ATargetPoint;
UCLASS()
class FPSGAME_API AFPSGuardController : public AAIController
{
GENERATED_BODY()
protected:
AFPSAIGuard* Guard;
UPROPERTY(EditDefaultsOnly, Category = "AI")
TSubclassOf<AActor> TargetClass;
// Create empty array for getter function to allocate returns into
TArray<AActor*> PatrolLocations;
public:
virtual void BeginPlay() override;
UFUNCTION()
void Patrol();
};
cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "FPSGuardController.h"
#include "FPSAIGuard.h"
#include "Kismet/GameplayStatics.h"
void AFPSGuardController::Patrol()
{
if (PatrolLocations.Num() > 0)
{
for (int32 i = 0; i < PatrolLocations.Num(); i++)
{
MoveToActor(PatrolLocations[i]);
}
Patrol();
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Array did not populate!!!"));
}
}
void AFPSGuardController::BeginPlay()
{
Guard = Cast<AFPSAIGuard>(GetCharacter());
if (Guard->GetCanPatrol())
{
UGameplayStatics::GetAllActorsOfClass(GetWorld(), TargetClass, PatrolLocations);
}
}
Only thing I can think of is that for w/e reason I cannot use the populated array in another method.
EDIT:
Sorry forgot to mention that when I run this in the editor, I keep getting the log message I setup in the Patrol method which is called if the PatrolLocations array is empty.