Information
I am working on getting mult-player and have been working on the HUD. Right now I’m just mocking up a simple HUD with the Canvas.
I am using a pawn class as my main “player”
I am using the built-in multi-player testing right from the client in the engine. I am testing with 2 players but have done tests with more.
I have linked my HUD through my game mode: HUDClass = ATestHUD::StaticClass();
I can successfully draw to the “1st” Player ONLY using the canvas function (For example: Canvas->K2_DrawLine(...)
)
The Problem
All subsequent players beyond the “1st” Player (who is also the server, and NO players if I have “Run Dedicated Server” Checked) are inaccessible in my HUD class.
What I am doing
I get my pawn Like so:
void ATestHUD::BeginPlay()
{
Super::BeginPlay();
if (GetOwningPlayerController() != NULL)
{
Player = Cast<ATestPawn>(GetOwningPlayerController()->GetPawn());
}
}
I then use the “Player” variable to get the screen location of the mouse and so forth. As stated. This works well for the “1st” player.
I then do the following:
void ATestHUD::DrawHUD()
{
Super::DrawHUD();
MyDraw();
}
void ATestHUD::MyDraw()
{
if (!Player) return;
Canvas->K2_DrawLine(Player->GetPlayerScreenLocation(), Player->GetFireDirection() * 550.0f + playerLoc, 1.5f, FLinearColor(0.4f, 0.4f, 0.4f, 0.1f));
}
The small check if (!Player) return;
saves me from crashes but is also the reason why subsequent players are not getting their HUDs drawn. So Obviously my Player variable is only valid for the “1st” Player.
How can I make it so I can draw my HUD on anyone who jumps in the game?
Thank you for checking it out.