Can't move client

I’ve been extending the ShooterGame template with a new GameMode (not based on the AShooterGameMode class, but on AGameMode). In single player my game mode works as inteded, so I decided to try and add multiplayer. My first problem is that the client can’t move and can’t see movement of other players / AI (bots appear static from the client’s perspective). Also, his camera (3rd person camera) is targetting him from the right side rather than from the back. He can rotate on the Z axis and shoot. Server works fine.

Also, changing the GameMode to any of the ones provided in the ShooterGame template makes the multiplayer work, so my problem must be on the GameMode / GameState / PlayerState (I’m using the ShooterPlayerController provided).

I initially thought that this might be the problem:

void AWaveGameMode::BeginPlay() {
	Super::BeginPlay();
	Super::HandleMatchHasStarted();

	for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
	{
		APlayerController* PlayerController = *Iterator;
		if (PlayerController && PlayerController->IsLocalPlayerController()) {
			AShooterHUD* ShooterHUD = Cast<AShooterHUD>(PlayerController->GetHUD());
			if (ShooterHUD) {
				ShooterHUD->SetMatchState(EShooterMatchState::Playing);
			}
		}
	}

	TArray<AActor*> Spawns;
	UGameplayStatics::GetAllActorsOfClass(GetWorld(), APlayerStart::StaticClass(), Spawns);
	for (AActor* Spawn : Spawns) {
		if (Spawn->ActorHasTag(SpawnTag)) {
			AISpawnPoints.Add(Spawn);
		}
	}
}

As the Client might not be getting the Playingmatch state, so I added this piece of code:

void AWaveGameMode::PostLogin(APlayerController* NewPlayer)
{
	Super::PostLogin(NewPlayer);

	// update spectator location for client
	AShooterPlayerController* NewPC = Cast<AShooterPlayerController>(NewPlayer);
	if (NewPC && NewPC->GetPawn() == NULL)
	{
		NewPC->ClientSetSpectatorCamera(NewPC->GetSpawnLocation(), NewPC->GetControlRotation());
	}

	// notify new player if match is already in progress
	if (NewPC && IsMatchInProgress())
	{
		NewPC->ClientGameStarted();
		NewPC->ClientStartOnlineGame();
	}
}

But didn’t work. Only spawned the crosshair on the client, but it still can’t move / see players moving.

I also tried adding this snippet to AShooterCharacter::Tick to help debug the problem:

	AShooterPlayerController* MyPC = Cast<AShooterPlayerController>(Controller);

	if (IsPlayerControlled()) {
		if (MyPC && MyPC->GetShooterHUD() && MyPC->GetShooterHUD()->GetMatchState() == EShooterMatchState::Playing) {
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, "playing");
		}
		else {
			if (MyPC) {
				if (!MyPC->GetHUD()) {
					GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Couldnt find hud");
				}
			}
			else {
				GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Couldn't find player controller");
			}
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "not playing");
		}
	}

And for Player 2 (ShooterController_1) I get the not playing and couldnt find hud messages. So I’m kind of lost here =\

How can I further debug / resolve what my problem is?

Turns out I was using AGameModeStateBase instead of AGameMode as a parent. Changing class parent solved the issue (don’t really know why, I’m guessing AGameMode has additional initialization, but not sure).

1 Like

You really saved me with this post, I’ve been looking for a solution for 3 days. I was using AGameMode with AGameStateBase and I fixed it by switching to AGameState. I found out that the base versions of AGameMode/AGameState are not usable with the non base versions, so I’m not sure if the issue is due to that incompatibility or if AGameStateBase just isn’t set up to replicate the game start to clients. Either way, this change resolved my client issues so thank you very much.

1 Like