I’m trying to use OverlapMulti to generate an array of hits, then use a for loop to build an array of the actors from those hits (so I can use the editor to visually verify that the correct objects are being detected and returned). However, this is producing a boatload of errors:
error C2440: ‘=’ : cannot convert from ‘TWeakObjectPtr’ to ‘AActor *’
error C2653: ‘overlaps’ : is not a class or namespace name
error C3861: ‘Num’: identifier not found
The first error, in particular, is what really has me confused- I thought I was comparing a pointer to a pointer, so there shouldn’t be any problems.
CharacterPerception.h:
public:
// Sets default values for this component's properties
UCharacterPerception();
void SenseStuff();
UPROPERTY(VisibleAnywhere)
AActor* myActor;
UPROPERTY(VisibleAnywhere)
TArray<FOverlapResult> overlaps;
UPROPERTY(VisibleAnywhere)
TArray<AActor> actorArray;
// Called when the game starts
virtual void BeginPlay() override;
// Called every frame
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
};
And the relevant function from CharacterPerception.cpp:
void UCharacterPerception::SenseStuff()
{
//TArray<FOverlapResult> overlaps;
AActor* Origin = this->GetOwner();
float Radius = 150.0f;
if (Origin->GetWorld()->OverlapMulti(
//output list
overlaps,
//origin location
Origin->GetActorLocation(),
//origin rotation
FQuat::Identity,
//collision channel
ECollisionChannel::ECC_Pawn,
//collision primitive
FCollisionShape::MakeSphere(Radius),
//collision parameters
FCollisionQueryParams()))
{
for (int i = 0; i < overlaps::Num();){
actorArray[i] = overlaps[i].Actor;
}
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "I see you!");
}
}