I have a PlayerController that receives input.
This controller, in particular, reacts to clicks.
When the click occurs for the first time, it spawns a pawn.
This works great, and i see my pawn appear where i clicked.
The pawn’s AIControllerClass is set up as a custom AI Controller.
Inside the pawn’s BeginPlay, it calls SpawnDefaultController.
After which the PlayerController gets the AI Controller that is spawned, and then calls MoveTo.
Nothing happens.
Here’s the PlayerController click event:
void APlayerPawnController::OnTouchBegin(ETouchIndex::Type FingerIndex, FVector Location)
{
if (FingerIndex == ETouchIndex::Touch1)
{
// Get pawn that belongs to ai controller and run its move method
// Go and get the mouse position of where the click occured.
FVector mouseLocation = MovementLogic->TransformMousePositionToScreenSpace(this);
FActorSpawnParameters spawnParams;
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
if (PlayerPawnClass)
{
FRotator rotation = FRotator(0.0f, 90.f, -90.f);
if (!PlayerPawn)
{
AActor* spawnedPawn = GetWorld()->SpawnActor(PlayerPawnClass.Get(), &mouseLocation, &rotation, spawnParams);
PlayerPawn = Cast<APlayerPawn>(spawnedPawn);
}
if (PlayerPawn && PlayerPawn->GetController())
{
APlayerPawnAIController* controller = Cast<APlayerPawnAIController>(PlayerPawn->GetController());
controller->MoveTo(mouseLocation); // Does nothing!
}
}
}
}
Here is my pawn’s constructor:
APlayerPawn::APlayerPawn()
{
PrimaryActorTick.bCanEverTick = true;
AIControllerClass = APlayerPawnAIController::StaticClass();
SetRootComponent(CreateDefaultSubobject<USceneComponent>(TEXT("PlayerPawn_RootComponent")));
CollisionComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("PlayerPawn_CollisionComponent"));
CollisionComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
}
and the BeginPlay:
// Called when the game starts or when spawned
void APlayerPawn::BeginPlay()
{
Super::BeginPlay();
SpawnDefaultController();
}
I have set up a navigation mesh for the AI.
Any ideas what i’m doing wrong?
I’m currently downloading the unreal engine symbols so i can debug MoveTo
… but i have a v slow connection, so was hoping someone could help
.
