AI Controller MoveTo does not move pawn

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 :slight_smile: .

Hah. A whole day later, the symbols dowloaded. Hurray for slow internet…

PathFollowingComponent.cpp ln 337.

if (!UpdateMovementComponent()) 

fails

UE_VLOG(GetOwner(), LogPathFollowing, Warning, TEXT("RequestMove: missing movement component"));
return FAIRequestID::InvalidRequest;

Not sure why yet. I thought all pawns had movement components. I’ll check if Pawns instantiate by default. Perhaps that’s the problem?

Okay. I see how this works. I’ve also found an article that has some cool detail in it:

https://unrealcpp.com/colliding-pawn/

Essentially the UPawnMovementComponent is abstract.

I Changed my APawn inheritance to ACharacter and now all the AI movement works. That’s annoying… it took 3 days to figure out that. Not entirely sure documentation was particularly helpful… But stepping through the code was.

I know it is old, but you could have seen the bug using the Visual logger instead of debug with symbol