I have edited the code to:
#include "AI_Bot_Controller.h"
#include "Perception/AIPerceptionComponent.h"
#include "Perception/AISenseConfig_Sight.h"
AAI_Bot_Controller::AAI_Bot_Controller()
{
PrimaryActorTick.bCanEverTick = true;
SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Config"));
PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("PerceptionComponent"));
//SetPerceptionComponent(*CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component")));
AISightRadius = 500.0f;
AISightAge = 5.0f;
AILoseSightRadius = AISightRadius + 50.0f;
AIFieldOfView = 90.0f;
SightConfig->SightRadius = AISightRadius;
SightConfig->LoseSightRadius = AILoseSightRadius;
SightConfig->PeripheralVisionAngleDegrees = AIFieldOfView;
SightConfig->SetMaxAge(AISightAge);
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
GetPerceptionComponent()->SetDominantSense(*SightConfig->GetSenseImplementation());
GetPerceptionComponent()->OnPerceptionUpdated.AddDynamic(this,&AAI_Bot_Controller::OnPawnDetected);
GetPerceptionComponent()->ConfigureSense(*SightConfig);
}
void AAI_Bot_Controller::BeginPlay()
{
Super::BeginPlay();
if ensure(!GetPerceptionComponent()) { return; }
if (GetPerceptionComponent() != nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("All System Set"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Some Problem"));
}
}
void AAI_Bot_Controller::OnPossess(APawn* Pawn)
{
Super::Possess(Pawn);
}
void AAI_Bot_Controller::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
}
FRotator AAI_Bot_Controller::GetControlRotation() const
{
if (GetPawn() == nullptr)
{
return FRotator(0.0f, 0.0f, 0.0f);
}
return FRotator(0.0f, GetPawn()->GetActorRotation().Yaw, 0.0f);
}
void AAI_Bot_Controller::OnPawnDetected(const TArray<AActor*>& DetectedPawns)
{
}
with the same error
Important detail the fail accrues here in UObjectArray.cpp
(I put a break point in BeginPlay and it crushed before)
int32 FUObjectArray::AllocateSerialNumber(int32 Index)
{
FUObjectItem* ObjectItem = IndexToObject(Index);
checkSlow(ObjectItem);
volatile int32 *SerialNumberPtr = &ObjectItem->SerialNumber;
int32 SerialNumber = *SerialNumberPtr;
if (!SerialNumber)
{
SerialNumber = MasterSerialNumber.Increment();
UE_CLOG(SerialNumber <= START_SERIAL_NUMBER, LogUObjectArray, Fatal, TEXT("UObject serial numbers overflowed (trying to allocate serial number %d)."), SerialNumber);
int32 ValueWas = FPlatformAtomics::InterlockedCompareExchange((int32*)SerialNumberPtr, SerialNumber, 0);
if (ValueWas != 0)
{
// someone else go it first, use their value
SerialNumber = ValueWas;
}
}
checkSlow(SerialNumber > START_SERIAL_NUMBER);
return SerialNumber;
}