So the game i am working on is multiplayer and has two teams, each with a different character and hud, which are assigned to the clients while they are on the respective teams. at what point after the client joins the server are the pawns spawned and the player controller told to take ownership of the spawned actor? i have overridden AGameMode::ChooseTeam(args) to assign the teams in the player states and tested it, so i know the teams are assigned correctly, but now i’m not sure where in the code i need to assign the hud class, spawn the correct pawn/character and tell the player’s playercontroller to take ownership based on which team they were assigned to. i assume i will be overriding one of the superclass functions to do this, but i’m not clear on the order of when they are executed after the client joins the server. what functions spawn the GameMode’s defaultpawnclass and defaulthudclass?
oh yeah! i forgot we can get into the source now, that will be a LOT more helpful than trying to figure out this stuff only through the headers. thank you for providing the function names anyway, that will save me some searching time and provide a good start point for what i need to do <3
If anyone comes across this question, I ended up solving my problem by making a base class for my game HUD that is a subclass of AHUD and handles all of the common ground between the two types of pawns i am using (such as the in-game menu/chat) and then reparented both of the other huds to my gameHUD. since “StartNewPlayer” is called after i have assigned the teams, i use that to assign the respective huds based on the teams as follows.
//set appropriate hud initial
void AMYGameMode::StartNewPlayer(APlayerController* NewPlayer)
{
Super::StartNewPlayer(NewPlayer);
AMYPlayerController* PCOwner = Cast<AMYPlayerController>(NewPlayer);
if (PCOwner)
{
AMYPlayerState* PState = Cast<AMYPlayerState>(PCOwner->PlayerState);
if (PState)
{
if (PState->GetTeamNum() == 1)// set team 1 hud
{
NewPlayer->ClientSetHUD(Team1Hud);
}
else if (PState->GetTeamNum() == 2)//set team 2 hud
{
NewPlayer->ClientSetHUD(Team2Hud);
}
}
}
}
I also overrode the RestartPlayer function, as my game mode is match based and it appears that StartNewPlayer is only called upon joining the server in PostLogin.
/**
* Override for resetting HUDs
*/
void AMYGameMode::RestartPlayer(AController* NewPlayer)
{
Super::RestartPlayer(NewPlayer);
AMYPlayerController* PCOwner = Cast<AMYPlayerController>(NewPlayer);
if (PCOwner)
{
AMYPlayerState* PState = Cast<AMYPlayerState>(PCOwner->PlayerState);
if (PState)
{
if (PState->GetTeamNum() == 1)// set team 1 hud
{
PCOwner->ClientSetHUD(Team1Hud);
}
else if (PState->GetTeamNum() == 2)//set team 2 hud
{
PCOwner->ClientSetHUD(Team2Hud);
}
}
}
}
where Team1Hud and Team2Hud are AMYGameMode class variables initialized in the constructor to Team1HudClass::StaticClass() and Team2HudClass::StaticClass() respectively. Hope this helps somebody.