Hi, I’m having problems with player spawning: I have set a function named “CreateSecondPlayer()”, called in my game mode’s BeginPlay() function. Currently it spawns the second player only sometimes, to avoid that randomness and make that player always spawn I’ve overriden the “ChoosePlayerStart” function.
The problem now is that I don’t know how to link or interrelate the two functions (CreatePlayer and ChoosePlayerStart) references to the player, because CreatePlayer needs the ID number / Index of the player and ChoosePlayerStart needs a AController*.
Now this is how it looks, obviously the ChoosePlayerStart is never applied to the player with index 1, created with CreatePlayer.
void AGameModePush::CreateSecondPlayer()
{
FString Error;
auto It1 = GetWorld()->GetPlayerControllerIterator();
APlayerController* Player1 = *It1;
AGameModePush::ChoosePlayerStart(Player1);
GEngine->GameViewport->CreatePlayer(1, Error, true);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Spawn time 1!"));
}
This is an outline of what I want to achieve:
void AGameModePush::CreateSecondPlayer()
{
FString Error;
//WARNING! That function doesn't exist!
APlayerController* Player1 = GetPlayerControllerByIndex(1);
AGameModePush::ChoosePlayerStart(Player1);
GEngine->GameViewport->CreatePlayer(1, Error, true);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Spawn time 1!"));
}
Here I’m inventing a function called “GetPlayerControllerByIndex” returns a pointer to the player controller with that index (APlayerController*).
As that function doesn’t exist, what would you do to solve this situation? Does it exist something like what I’m looking for directly, a function that returns the controller from the index you give it? Or is something different required? I’m pretty lost on this.