Hi all,
I’m trying to use function UGameplayStatics::GetAllActorsOfClass to get all AI Pawn in my scene, but it leads to an error.
ERROR:
D:\UE_projects\SensorSystem\Source\SensorSystem\Private\SensorCharacter.cpp(45) : error C2664: 'void UGameplayStatics::GetAllActorsOfClass(const UObject *,TSubclassOf<AActor>,TArray<AActor *,FDefaultAllocator> &)': cannot convert argument 3 from 'TArray<ASensorAICharacter *,FDefaultAllocator>' to 'TArray<AActor *,FDefaultAllocator> &'
Header:
#pragma once
#include "CoreMinimal.h"
#include "SensorSystemCharacter.h"
#include "SensorCharacter.generated.h"
class ASensorAICharacter;
/**
*
*/
UCLASS()
class SENSORSYSTEM_API ASensorCharacter : public ASensorSystemCharacter
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = Abilities)
void Fire(bool& IsFire);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BaseStats)
bool IsFire = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BaseStats)
float AttackSpeed = 2.f;
void FindNearestAIPawn(UObject* ThisLevel, TArray<ASensorAICharacter*> ArrayOfAIPawn);
};
Cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "SensorCharacter.h"
#include "SensorAICharacter.h"
//#include "../Runtime/Engine/Machine/BaseFrame.h"
#include "../Runtime/Engine/Classes/Kismet/GameplayStatics.h"
void ASensorCharacter::Fire(bool& IsFire)
{
IsFire = true;
TArray<ASensorAICharacter*> FoundActors;
FindNearestAIPawn(Cast<UObject>(GetWorld()), FoundActors);
}
void ASensorCharacter::FindNearestAIPawn(UObject* ThisLevel, TArray<ASensorAICharacter*> ArrayOfAIPawn)
{
UGameplayStatics::GetAllActorsOfClass(ThisLevel, ASensorAICharacter::StaticClass(), ArrayOfAIPawn);
for (AActor* TActor : ArrayOfAIPawn)
{
ASensorAICharacter* MyActor = Cast<ASensorAICharacter>(TActor);
if (MyActor != nullptr)
{
//Calculate distance
}
}
}
I’ve tried to google out all solution but there’s no any match solution
Thank you!