Hi…
As you know, it is not possible to access Canvas from any part from the HUD other than the DrawHUD function.
So I am planning to use this way. But I doubt it is the most optimal way to do it.
This is my character class
APlayerController* MyPC = Cast<APlayerController>(Controller);
AMyProjectHUD* MyHUD;
FVector EndLocation;
MyHUD = nullptr;
if (MyPC)
{
MyHUD = Cast<AMyProjectHUD>(MyPC->GetHUD());
}
if (MyHUD)
{
MyHUD->bIsFiringCast = true;
MyHUD->DrawHUD();
}
This my HUD class
void AMyProjectHUD::DrawHUD()
{
if(bIsFiringCast == false)
{
Super::DrawHUD();
// Draw very simple crosshair
// find center of the Canvas
const FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
// offset by half the texture's dimensions so that the center of the texture aligns with the center of the Canvas
const FVector2D CrosshairDrawPosition((Center.X - (CrosshairTex->GetSurfaceWidth() * 0.5)),
(Center.Y - (CrosshairTex->GetSurfaceHeight() * 0.5f)));
// draw the crosshair
FCanvasTileItem TileItem(CrosshairDrawPosition, CrosshairTex->Resource, FLinearColor::White);
TileItem.BlendMode = SE_BLEND_Translucent;
Canvas->DrawItem(TileItem);
}
else
{
//GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red,TEXT("WORKS"));
//bIsFiringCast = false;
}
}
But using this kind of lags my game. Although I am not 100% sure if it actually lags the game.