Top down movement with mouse, replication

Hello everyone,

There is something I don’t understand with PlayerController and AIPlayerController with C++.

So here’s my situation:
I want to create a TopDown mouse driven movement multiplayer online. I did implement movement, using the CharacterMovement class. When a Player clicks, I compute the clicked position in 3D with a mouse to screen ray : PlayerController::GetHitResultUnderCursorByChannel(…) and manually add the direction vector to the AddMovementInput(FVector) method. It works fine.

Now, I’ve seen some examples of people using AAIController::MoveToLocation method. I think this is exactly what I need and it must be a better implementation than mine. But whenever I try to Cast my Controller member, it returns nullptr.

I’ve seen quite a few posts about C++ integration of AAIController. Here is my Pawn config after seeing these posts:

image

In my character cpp, I do something like this (client side now, but tried server side):

PlayerController->GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult);

if (Controller != nullptr)
{
	AAIController* AIController = Cast<AAIController>(Controller);

	if (AIController != nullptr)
	{
		AIController->MoveToLocation(TargetPosition);
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Cast to AIController failed"));
	}
}

As far as I understand, the Controller is either a APlayerController or a AIController but I need both. I don’t really know how to combine both and could not find enough informations.

Has anyone any idea on how to achieve this correctly ?

Thanks,
Pantoine