Simple Move not working with Possessed Characters

I know this post was a long time ago but I hit the same problem and figured out what was going on.

The issue is that in a client navigation case the controller’s UPathFollowingComponent doesn’t get updated after possessing a new pawn with its new movement component. This happens because the UPathFollowingComponent normally gets the update from the Controllers GetOnNewPawnNotifier event which only fires on the server. This means that when SimpleMoveToLocation is called the check for PFollowComp->IsPathFollowingAllowed() fails (it has a null check on the movement component).

The workaround I went with (C++ required I’m afraid) is to implement a wrapper to SimpleMoveToLocation that reinitializes the Path Following Component if necessary, here’s an example:

void AMySamplePlayerController::SimpleClientNavMove(const FVector& Destination)
{
	UPathFollowingComponent* PathFollowingComp = FindComponentByClass<UPathFollowingComponent>();
	if (PathFollowingComp == nullptr)
	{
		PathFollowingComp = NewObject<UPathFollowingComponent>(this);
		PathFollowingComp->RegisterComponentWithWorld(GetWorld());
		PathFollowingComp->Initialize();
	}
	
	if (!PathFollowingComp->IsPathFollowingAllowed())
	{
		// After a client respawn we need to reinitialize the path following component
		// The default code path that sorts this out only fires on the server after a Possess
		PathFollowingComp->Initialize();
	}

	UAIBlueprintHelperLibrary::SimpleMoveToLocation(this, Destination);
}
1 Like