I started with the Twin Stick Shooter C++ template. I have my space ship pawn class and have added in a lot of functionality with C++ and want to keep going.
My main goal is to make a multi-player version of a twin stick shooter. I have replicated pawn movement and firing and so forth but I am getting hung up on spawing a new pawn once you are destroyed.
I am using the built in multiplayer testing within the launcher (I just set the number of players to 2+ and test everything)
I have done all the inputs and movement handling inside the pawn class and I do NOT have a custom player controller class, and I’m wondering if that’s the source of some of my problems.
I have no custom spawning code when the game begins, the game just gives me the number of pawns I tell it to from the editor.
When my pawn dies I do this in the pawn class: (This is called when the player get’s killed)
void ATestPawn::Explode()
{
GEngine->AddOnScreenDebugMessage(1, 15.0f, FColor::Red, "I'm a dead man.");
ShipMeshComponent->SetVisibility(false);
UnPossessed();
auto gameMode = GetWorld()->GetAuthGameMode();
auto TestGameMode = Cast<ATestGameMode>(gameMode);
TestGameMode->RegisterPawnDeath(GetController()->CastToPlayerController());
Destroy();
}
And in my Game Mode I’m doing this:
void ATestGameMode::RegisterPawnDeath(APlayerController* PlayerController)
{
//if (!PlayerController) return;
FActorSpawnParameters params;
params.bNoCollisionFail = true;
params.Owner = this;
params.Instigator = NULL;
params.bDeferConstruction = false;
auto PlayerStart = GetWorld()->SpawnActor<APlayerStart>(APlayerStart::StaticClass(), FVector(0, 0, 210.0f), FRotator::ZeroRotator, params);
PlayerController->Possess(SpawnDefaultPawnFor(PlayerController, PlayerStart));
}
This code works for the player who is also acting as the host/server but it does not working for any other players.
My problem is that I don’t really understand player controllers. Do I have to manually assign them to the pawns? Do I need to override the default behavior of spawning in a new player when the game starts and then have the server assign a pawn a player controller that the server keeps a record of? If that’s the case How do I do that? I don’t really know where these player controllers are coming from and how to properly manage them.
Any insights would be very helpful thank you.